What does your .NET Webservice look like?
I had the same effect using ksoap 2.3 with code.google.com . I followed the tutorial on Draft Code (this is a great BTW.)
And every time I used
Integer result = (Integer)envelope.getResponse();
to get the result of my web service (regardless of type, I tried Object, String, int) I came across an org.ksoap2.serialization.SoapPrimitive exception.
I found a solution (workaround). The first thing I needed to do was remove the SoapRpcMethod () attribute from my webservice methods.
[SoapRpcMethod(), WebMethod] public Object GetInteger1(int i) {
Then I changed my Android code to:
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
However, I get a SoapPrimitive object that has a “value” that is private. Fortunately, the value is passed using the toString() method, so I use Integer.parseInt(result.toString()) to get my value, which is enough for me, because I don't have any complex types that I need to get from my web service.
Here is the complete source:
private static final String SOAP_ACTION = "http://tempuri.org/GetInteger2"; private static final String METHOD_NAME = "GetInteger2"; private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = "http://10.0.2.2:4711/Service1.asmx"; public int GetInteger2() throws IOException, XmlPullParserException { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo pi = new PropertyInfo(); pi.setName("i"); pi.setValue(123); request.addProperty(pi); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); androidHttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); return Integer.parseInt(result.toString()); }
Jürgen Steinblock Oct 05 '09 at 17:15 2009-10-05 17:15
source share