Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can any one help me out to clear this error?

I have done all the settings... Selected the jar file in the java build path also.. my folder also in the name of libs only... when I connect my webservice with my android app using a login button the error shows it up always....

my app contains the certificate problem with a expired certificate webpage.. and I added the code to bypass the certificate error...

But this SoapSerialization error always occurs when I click the login button..

and here Is my code

    package com.test.mqilynx;


import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
 StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
   StrictMode.setThreadPolicy(policy);
}
Button loginb = (Button) findViewById(R.id.button1);
loginb.setOnClickListener( new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText uname = (EditText) findViewById(R.id.editText1);
EditText pwd = (EditText) findViewById(R.id.editText2);
String ustr = uname.getText().toString();
        String pstr = pwd.getText().toString();
        if (ustr.isEmpty() && pstr.isEmpty()){
            Toast to = Toast.makeText(MainActivity.this,"Please Login credentials",Toast.LENGTH_SHORT);
            to.setGravity(Gravity.CENTER, 0, 0);
            to.show();
        }
        else
        { if (ustr.isEmpty() || pstr.isEmpty())
            {
             if(ustr.isEmpty()){
             Toast to = Toast.makeText(MainActivity.this,"Please Enter Username",Toast.LENGTH_SHORT);
            to.setGravity(Gravity.CENTER, 0, 0);
            to.show();}
            else{
                Toast to = Toast.makeText(MainActivity.this,"Please Enter Password",Toast.LENGTH_SHORT);
                to.setGravity(Gravity.CENTER, 0, 0);
                to.show();
            }
                }
             else 
             {
                // Toast.makeText(getBaseContext(),"Welcome! " + ustr + " Pwd: "+ pstr,Toast.LENGTH_SHORT).show();


                 String METHOD_NAME = "Login";
                 String NAMESPACE = "https://www.qilynx.com/loadsoap.php";
                 String SOAP_ACTION = "https://www.qilynx.com/loadsoap.php/Login";
                // String URL = "https://auth:[email protected]/loadsoap.php?desc";
                 String URL = "https://www.qilynx.com:443/loadsoap.php";
                 SoapObject userReq = new SoapObject(NAMESPACE,METHOD_NAME);
                 userReq.addProperty("user",ustr);
                 userReq.addProperty("pass",pstr);
                 System.out.println("user: " + "" + ustr + ":" + "Pwd: " + pstr);

            //   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            //   request.addProperty("Login", userReq);

                 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                // envelope.bodyOut = request;
                 envelope.dotNet=true;
                 envelope.setOutputSoapObject(userReq);
                 Log.e("Value of Req", userReq.toString());
                 Log.e("Value of Envelope", envelope.toString());
                // Log.i("bodyenv", envelope.bodyOut.toString());

                 HttpTransportSE androidHTTPTransport = new HttpTransportSE(URL);

                 //By-passing certificate - START
                // Create a trust manager that does not validate certificate chains



                 TrustManager[] trustAllCerts = new TrustManager[]{
                     new X509TrustManager() {
                         public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                             return null;
                         }
                         public void checkClientTrusted(
                             java.security.cert.X509Certificate[] certs, String authType) {
                         }
                         public void checkServerTrusted(
                             java.security.cert.X509Certificate[] certs, String authType)  {
                         }
                     }
                 };

                 // Install the all-trusting trust manager
                 try {
                     SSLContext sc = SSLContext.getInstance("SSL");
                     sc.init(null, trustAllCerts, new java.security.SecureRandom());
                     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
                 } catch (Exception e) {
                     e.printStackTrace();
                 }


                 // By-passing certificate - END
                 try{
                     System.out.println("I AM IN TRY");
                     System.out.println("envelope1 "+envelope);
                     androidHTTPTransport.setXmlVersionTag("<?xml version="1.0" encoding="UTF-8"?>");
                     System.out.println("Before Bp1");
                     System.out.println("Bp 1");
                     androidHTTPTransport.call(SOAP_ACTION,envelope);
                     System.out.println("after Bp1");
                     System.out.println("Bp 2");
                     SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                        Log.v("TAG",String.valueOf(resultsRequestSOAP));

                     System.out.println("envelope2 "+envelope); 
                     System.out.println("before resp");
                     SoapObject resp = (SoapObject) envelope.getResponse();
                     Log.i("return", resp.toString());
                     boolean check = Boolean.parseBoolean(resp.getProperty("result").toString());
                     if(check)
                     {
                         System.out.println("SUCCESS LOGIN");
                         /*Toast to = Toast.makeText(MainActivity.this,"Logged In",Toast.LENGTH_SHORT);
                            to.setGravity(Gravity.CENTER, 0, 0);
                            to.show(); */
                     }

                     else
                     {
                         /*Toast to = Toast.makeText(MainActivity.this,"Failed",Toast.LENGTH_SHORT);
                            to.setGravity(Gravity.CENTER, 0, 0);
                            to.show();*/
                         System.out.println("LOGIN FAILED");
                     }

                 }

                 catch(Exception e)
                 {
                     System.out.println("I AM IN ERROR");
                    e.printStackTrace(); 
                 }
             }
        }
        }
    });

}

}

The code which have the line androidHTTPTransport.call(SOAP_ACTION,envelope); from this line the code is not working...

the logcat showing the error like below

12-24 06:17:13.968: E/Value of Envelope(13752): org.ksoap2.serialization.SoapSerializationEnvelope@417c87b0
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
297 views
Welcome To Ask or Share your Answers For Others

1 Answer

Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it.Mark all checkboxes and Click on Apply and clean the project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...