Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How does your .NET Webservice look like?</p> <p>I had the same effect using <a href="http://code.google.com/p/ksoap2-android/" rel="noreferrer">ksoap 2.3 from code.google.com</a>. I followed the tutorial on <a href="http://www.codeproject.com/KB/webservices/CallWebServiceFromkSOAP.aspx" rel="noreferrer">The Code Project</a> (which is great BTW.)</p> <p>And everytime I used</p> <pre><code> Integer result = (Integer)envelope.getResponse(); </code></pre> <p>to get the result of a my webservice (regardless of the type, I tried Object, String, int) I ran into the <code>org.ksoap2.serialization.SoapPrimitive</code> exception.</p> <p>I found a solution (workaround). The first thing I had to do was to remove the "SoapRpcMethod() attribute from my webservice methods.</p> <pre><code> [SoapRpcMethod(), WebMethod] public Object GetInteger1(int i) { // android device will throw exception return 0; } [WebMethod] public Object GetInteger2(int i) { // android device will get the value return 0; } </code></pre> <p>Then I changed my Android code to:</p> <pre><code> SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); </code></pre> <p>However, I get a SoapPrimitive object, which has a "value" filed that is private. Luckily the value is passed through the <code>toString()</code> method, so I use <code>Integer.parseInt(result.toString())</code> 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.</p> <p>Here is the full source:</p> <pre><code>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()); } </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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