Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving custom objects from SOAP-based .NET web service in Android
    primarykey
    data
    text
    <p>I'm developing an Android app which needs to connect to a .NET SOAP web service and generate/populate a number of objects from the response. I'm totally new to web services and SOAP, and relatively new to Android. The web service has already been built (not by me). </p> <p>I've been trying to find info on connecting to SOAP web services in Android. The two basic suggestions seem to be: </p> <ol> <li>Don't use SOAP,</li> <li>If you do use SOAP, use KSOAP2. </li> </ol> <p>I've looked at various tutorials for KSOAP2 but they all seem to deal only with the most basic, primitive types, such as sending 2 ints to get 1 int back, or sending and receiving strings;, however, I need to send custom objects back and forth. </p> <p>Is it possible to send and receive custom objects using KSOAP2? If so, how easy/difficult is this? Does the XML have to be parsed to create/populate the objects "by hand"? </p> <p><strong>EDIT/UPDATE:</strong> After trying for a while to connect to the existing webservice (takes a String and returns a complex object), and getting an error, I decided to try a simpler approach. I connected to a simpler webservice which takes no parameters, and returns an int. This simpler webservice is hosted in the same place as the original one, and the simple one now works fine for me.</p> <p><strong>FURTHER UPDATE:</strong> All working fine now! Turns out I just had a capitalisation error which was throwing off my parameter. </p> <p>The final problem was "national" versus "National". Here's the soapUI-generated code:</p> <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"&gt; &lt;soapenv:Header/&gt; &lt;soapenv:Body&gt; &lt;tem:GetClientByNationalID&gt; &lt;!--Optional:--&gt; &lt;tem:nationalID&gt;XXXXXXX&lt;/tem:nationalID&gt; &lt;/tem:GetClientByNationalID&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt; </code></pre> <p>And the request code which was being generated by my Java: </p> <pre><code>&lt;v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;v:Header /&gt; &lt;v:Body&gt; &lt;GetClientByNationalID xmlns="http://tempuri.org/" id="o0" c:root="1"&gt; &lt;NationalID i:type="d:string"&gt; XXXXXXXX &lt;/NationalID&gt; &lt;/GetClientByNationalID&gt; &lt;/v:Body&gt; &lt;/v:Envelope&gt; </code></pre> <p>My final java code is:</p> <pre><code>public void webServiceCall() { String NAMESPACE = "http://tempuri.org/"; String METHOD_NAME = "GetClientByNationalID"; String SOAP_ACTION = "http://tempuri.org/IClientService/GetClientByNationalID"; // unsecure service String URL = "http://XXXXXXXXXXXXXXXXXXXX.net/FPUnSecureService/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); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); envelope.addMapping(NAMESPACE, "GetClientByNationalID", new ClientID().getClass()); Marshal floatMarshal = new MarshalFloat(); floatMarshal.register(envelope); HttpTransportSE t = new HttpTransportSE(URL); ClientID client = new ClientID(); t.debug = true; try { Log.i("webServiceCall", "Trying call to web service"); t.call(SOAP_ACTION, envelope); SoapObject response = (SoapObject) envelope.getResponse(); 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)); } 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>I am still confused about these lines:</p> <pre><code>envelope.addMapping(NAMESPACE, "GetClientByNationalID", new ClientID(). Marshal floatMarshal = new MarshalFloat(); floatMarshal.register(envelope); </code></pre> <p>I think I added the Marshal parts when I was passing an object as a parameter, I'm not sure if I still need them. I'm also not sure about the addMapping call either, and what I should have in there. Thanks. </p>
    singulars
    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.
 

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