Note that there are some explanatory texts on larger screens.

plurals
  1. POKSOAP2 for Android gives
    text
    copied!<p>I'm trying to access a web service whose WSDL is at <a href="http://srilanka.lk:9080/services/CropServiceProxy?wsdl" rel="nofollow">http://srilanka.lk:9080/services/CropServiceProxy?wsdl</a> . Using SoapUI I sent a request and successfully got a response. </p> <p>Then using KSoap2 for Android I tried to get a response. But all I get is a SoapFault Error. The code is as follows. </p> <p>String NAMESPACE = "http://schemas.icta.lk/xsd/crop/handler/v1";</p> <pre><code> String URL = "http://www.srilanka.lk:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint"; String method_name = "getCropDataList"; String SOAP_ACTION = method_name; SoapObject request = new SoapObject(NAMESPACE, method_name); String crop_code_str = String.valueOf(code.getText().toString()); System.out.println(crop_code_str); System.out.println(request.toString()); request.addProperty("code", crop_code_str ); System.out.println(request.getProperty("code").toString()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); envelope.setOutputSoapObject(request); System.out.println("body out : " + envelope.bodyOut.toString()); HttpTransportSE http_transport = new HttpTransportSE(URL); try { http_transport.call(SOAP_ACTION, envelope); System.out.println(envelope.bodyIn.toString()); } catch (Exception e) { e.printStackTrace(); answer.setText("error caught"); } </code></pre> <p>This results in the following.</p> <pre><code>W/System.err( 394): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG &lt;{http://schemas.xmlsoap.org/soap/envelope/}soapenv:Envelope&gt;@1:114 in java.io.InputStreamReader@43e81258) </code></pre> <p>I tried with VER11 but it then gives the following error as the bodyIn.</p> <pre><code>I/System.out( 365): SoapFault - faultcode: 'soapenv:Server' faultstring: 'org.apache.axis2.databinding.ADBException: Unexpected subelement code' faultactor: 'null' detail: org.kxml2.kdom.Node@43e84648 </code></pre> <p>Is this something wrong with Ksoap2 for android? Then is there another way that a web service can be consumed in Android? (Only SOAP is available)</p> <p>UPDATE: I tried the KvmSerializable interface for the complext type. Following is my code. I still get the same errors. The XMLPullParser error is being thrown at the http_transport.call line.</p> <p>This is the complex type implementation at the client side. I have only the WSDL. </p> <pre><code>public class CropInfo implements KvmSerializable { private String name; private float price; private String location; @Override public Object getProperty(int arg0) { switch (arg0){ case 0: return name; case 1: return price; case 2: return location; default: return null; } } @Override public int getPropertyCount() { return 3; } @Override public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { switch (arg0){ case 0: arg2.type = PropertyInfo.STRING_CLASS; arg2.name = "Name"; break; case 1: arg2.type = Float.class; arg2.name = "Price"; break; case 2: arg2.type = PropertyInfo.STRING_CLASS; arg2.name = "Location"; break; default: break; } } @Override public void setProperty(int arg0, Object arg1) { switch(arg0){ case 0: name = arg1.toString(); break; case 1: price = Float.parseFloat(arg1.toString()); case 2: location = arg1.toString(); default: break; } } } </code></pre> <p>The modified code to access and parse the response of the web service.</p> <p>String NAMESPACE = "http://schemas.icta.lk/xsd/crop/handler/v1/"; String URL = "http://www.srilanka.lk:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint"; String method_name = "getCropDataList"; String SOAP_ACTION = "http://schemas.icta.lk/xsd/crop/handler/v1/getCropDataList";</p> <pre><code> SoapObject soap_request = new SoapObject(NAMESPACE, method_name); String crop_code_str = String.valueOf(code.getText().toString()); System.out.println(crop_code_str); System.out.println(soap_request.toString()); soap_request.addProperty("code", crop_code_str ); System.out.println(soap_request.getProperty("code").toString()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); envelope.setOutputSoapObject(soap_request); envelope.addMapping(NAMESPACE, "cropInfo", CropInfo.class); //envelope.dotNet=true; Marshal floatMarshal = new MarshalFloat(); floatMarshal.register(envelope); System.out.println("body out : " + envelope.bodyOut.toString()); //AndroidHttpTransport http_transport = new AndroidHttpTransport(URL); HttpTransportSE http_transport = new HttpTransportSE(URL); try { //error comes from this call http_transport.call(SOAP_ACTION, envelope); Vector&lt;CropInfo&gt; result_array = (Vector&lt;CropInfo&gt;)envelope.getResponse(); if(result_array != null){ for (CropInfo current_crop: result_array){ System.out.println(current_crop.getName()); System.out.println(Float.toString(current_crop.getPrice())); } } } catch (Exception e) { e.printStackTrace(); answer.setText("error caught"); } </code></pre>
 

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