Note that there are some explanatory texts on larger screens.

plurals
  1. POConnect to secure webservice in Android using KSoap2
    primarykey
    data
    text
    <p>I'm trying to connect to a secure webservice in an Android app using KSoap2, but having some difficulty. I've looked at a few tutorials and other questions/answers on StackOverflow but so far nothing has worked. </p> <p>I have an identical webservice on an unsecure service, and I can connect to this just fine. I am not sure if I need to setup an SSL connection manually or if KSoap2 should handle all that, when using the secure service? </p> <p>I'm trying to use the solution found <a href="https://gist.github.com/908048" rel="nofollow">here</a> but I'm getting the following error: </p> <pre><code>java.io.IOException: Relative path: https://XXXXXXXX.net/FPSecureService/ClientService.svc </code></pre> <p>When using SoapUI I can connect to the secure webservice no problem - I have to set a username and password and WSS-Password Type to "PasswordText", and then it works fine. I have tried to get my Java code to mimic the SoapUI-generated request code as best I can. All the header stuff I'm adding is to try to make it identical to the SoapUI-generated request, but this hasn't worked. </p> <p>Here is the my code calling the web service:</p> <p>public void secureWebServiceCall() { </p> <pre><code> // secure service String mUrl = "https://XXXXXXXX.net/FPSecureService/ClientService.svc"; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); String clientID = "XXXXXXX"; PropertyInfo pi = new PropertyInfo(); pi.setName("nationalID"); pi.setValue(clientID); pi.setType(clientID.getClass()); request.addProperty(pi); // build Envelope SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; // Apdd mapping and marshalling envelope.addMapping(NAMESPACE, "GetClientByNationalID", new ClientID().getClass()); Marshal floatMarshal = new MarshalFloat(); floatMarshal.register(envelope); // Construct soap envelope headers Element[] header = new Element[1]; header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security"); header[0].setAttribute(null, "mustUnderstand","1"); Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken"); usernametoken.setAttribute("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "UsernameToken-1"); header[0].addChild(Node.ELEMENT,usernametoken); Element username = new Element().createElement(null, "n0:Username"); username.addChild(Node.TEXT, "XXXXXXXX"); usernametoken.addChild(Node.ELEMENT, username); Element pass = new Element().createElement(null, "n0:Password"); pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); pass.addChild(Node.TEXT, "XXXXXXX"); usernametoken.addChild(Node.ELEMENT, pass); Element nonce = new Element().createElement(null, "n0:Nonce"); nonce.setAttribute(null, "EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); nonce.addChild(Node.TEXT, "eic5EdyTomcBLocwyph5Mw=="); usernametoken.addChild(Node.ELEMENT, nonce); Element created = new Element().createElement(null, "n0:Created"); created.addChild(Node.TEXT, "2012-02-08T09:47:55.225Z"); usernametoken.addChild(Node.ELEMENT, created); envelope.headerOut = header; // Set Output Soap Object as Request envelope.setOutputSoapObject(request); HttpTransportSE t = new HttpTransportSE(mUrl); AndroidInsecureKeepAliveHttpsTransportSE androidTransport = new AndroidInsecureKeepAliveHttpsTransportSE("XXXXXXXX.net", 80, mUrl, 50000); ClientID client = new ClientID(); t.debug = true; try { Log.i("webServiceCall", "Trying call to web service"); // t.call(SOAP_ACTION, envelope); androidTransport.call(SOAP_ACTION, envelope); SoapObject response = (SoapObject) envelope.getResponse(); TextView tv = (TextView) findViewById(R.id.textView1); tv.setText(response.getPropertyAsString(3)); Log.i("success", response.getPropertyAsString(0)); Log.i("success", response.getPropertyAsString(1)); Log.i("success", response.getPropertyAsString(2)); Log.i("success", response.getPropertyAsString(3)); Log.i("success", response.getPropertyAsString(4)); System.out.println("Request: " + t.requestDump); System.out.println("Response: " + t.responseDump); } catch (Exception e) { Log.e("webServiceCall", "Error calling webservice."); e.printStackTrace(); System.out.println("Request: " + t.requestDump); System.out.println("Response: " + t.responseDump); } } </code></pre> <p>Does anyone have any ideas? I felt like I might be finally getting somewhere with the AndroidInsecureHttpsServiceConnection and all that SSL stuff, but it doesn't work. I can't help feeling I've made a simple mistake somewhere but I don't know what it is. That "Relative path" error makes me feel like it's something very simple to do with the paramaters I'm giving the connection, but I'm new to that stuff and not sure what parameters I should be specifying and how I should be specifying them. </p> <p>Any help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload