i'm trying to connect an asmx web service which has SSL enabled certificate from symantec. The web service works fine in browser with green indication. But unable to connect the webservice with android using ksoap library. I have added the public key of certificate(.cer file) in the aseets folder and added it to the trustmanager.
Asked
Active
Viewed 682 times
-1
-
I faced same issue some time back and finally I call the webservice using normal java HTTP Connection. – Naveen Ramawat Jul 31 '15 at 09:28
-
Yes, In background finally http url connection works ... see how to call soap webservice using http url connection. http://stackoverflow.com/questions/31286722/how-to-send-raw-soap-request-in-java/31287188#31287188 – Naveen Ramawat Jul 31 '15 at 09:31
-
But using https is secured with SSL. http doesn't gives the secured path in between client and server. – Shinurag KR Jul 31 '15 at 09:33
-
Please use HttpsUrlConnection. – Naveen Ramawat Jul 31 '15 at 11:16
-
@NaveenRamawat let me try. Thank you. – Shinurag KR Aug 03 '15 at 03:32
-
Its works perfect right now. done minor changes in ksoap2 http://stackoverflow.com/questions/3440062/ksoap-2-android-with-https – Shinurag KR Aug 03 '15 at 08:09
1 Answers
2
Here is the complete solution for how to handle SSL over android and c# webservice by using ksoap.
- customise your org.ksoap2.transport.org.ksoap2.transport class constructor like this
public HttpTransportSE(Certificate ca, String url) {
super(ca, url);
}
2. change some codes in org.ksoap2.transport.ServiceConnectionSE class
public ServiceConnectionSE(Certificate ca, String url) throws IOException
{
// Create a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore;
SSLContext context = null;
try {
keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager
context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Tell the URLConnection to use a SocketFactory from our SSLContext
connection = (HttpsURLConnection) new URL(url).openConnection();
connection.setSSLSocketFactory(context.getSocketFactory());
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
}
- And send your Certificate ca
CertificateFactory cf = CertificateFactory.getInstance("X.509");
AssetManager assetManager = getAssets();
InputStream caInput = new BufferedInputStream(assetManager.open("your_cert.cer"));
Certificate ca = cf.generateCertificate(caInput);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(ca, url);

Shinurag KR
- 131
- 3
- 13