My ksoap2 webservice and webService-client works well with HttpTransportSE. Now I want to use SSL with a trusted certificat. To use the webservice on Tomcat SSL I added Https Transport Reciver in the Axis2.xml and I think the webservice works. This is my SSL webservice:
<https://myURL.de:8443/WebProject_KomplexeObjekte_SSL/services/HelloWorldWS?wsdl>?
The next step was to changed httptransportSE(URL) to httpstransportSE(HOST, PORT, FILE, TIMEOUT) in my client. This is my client:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.HttpsServiceConnectionSE;
import org.ksoap2.transport.HttpsTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WSClientKomplexeObjekteActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.chathura.com/getCategoryObject";
private static final String METHOD_NAME = "getCategoryObject";
private static final String NAMESPACE = "http://ws.chathura.com";
private static final String NAMESPACE2 = "http://ws.chathura.com/xsd";
private static final String HOST = "myURL.de";
private static final int PORT = 8443;
private static final String FILE = "/WebProject_KomplexeObjekte_SSL/services/HelloWorldWS?wsdl";
private static final int TIMEOUT = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.textview1);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Category C = new Category();
C.setCategoryId(1);
C.setDescription("Client Beschreibung");
C.setName("Client Name");
Request.addProperty("obj", C);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(Request);
envelope.addMapping(NAMESPACE2, C.getClass().getSimpleName(), C.getClass());
HttpsTransportSE androidHttpsTransport = new HttpsTransportSE(HOST, PORT, FILE, TIMEOUT);
Category ans = null;
try {
androidHttpsTransport.call(SOAP_ACTION, envelope);
ans = (Category)envelope.getResponse();
tv.setText("CategoryId: " + ans.getCategoryId() + "\nName: " + ans.getName() + "\nDescription: " + ans.getDescription());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Now i get this exception in Logcat:
W/System.err(619): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Because of this exception I tried to include a keystore which includes the certificate used on my tomcat for ssl. You can see this code in comments. That was without success. I got the following exception:
E/AndroidRuntime(654): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.bachelor.marcel/de.bachelor.marcel.WSClientKomplexeObjekteActivity}: java.lang.NullPointerException
Ok... I solved the Problem myself. The client-code was not the problem. It works very well. The only problem was on server side. Android don't trust my server because i forgot to include the root-certificate. So if you have the same problem you can check your ssl server with http://www.sslshopper.com/ssl-checker.html#