Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing objects to wcf soap service from android using ksoap2; it sends and receives 0
    primarykey
    data
    text
    <p>I am trying to use ksoap2 to access methods in a wcf soap service from android. I was able to successfully pass simple type parameters to the method, it worked fine. But when I try to pass objects, the wcf method is receiving 0 for all the object values.</p> <p>I have used the same SOAP service with a WP7 app and it runs fine.</p> <p>I have 2 methods in my service, ksoapadd and addParam. addParam takes in two integer and returns their sum(this works). ksoapadd takes in an object of class testadd which has two integer elements and ksoapadd returns their sum(this gets and sends 0).</p> <p>I think it has something to do with the namespace but I can't figure out how to resolve it. I have been doing trial and error to get the soap request right, but no luck yet.</p> <p>Can anyone help me figure out what to do? I have tried many options which somehow helped other people with similar problem but with no avail. </p> <p>here is my wsdl:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; -&lt;wsdl:definitions xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/" name="Service1"&gt; -&lt;wsdl:types&gt; -&lt;xsd:schema targetNamespace="http://tempuri.org/Imports"&gt; &lt;xsd:import namespace="http://tempuri.org/" schemaLocation="http://localhost:51086/Service1.svc?xsd=xsd0"/&gt; &lt;xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="http://localhost:51086/Service1.svc?xsd=xsd1"/&gt; &lt;xsd:import namespace="http://schemas.datacontract.org/2004/07/InsertIntoUserWCF" schemaLocation="http://localhost:51086/Service1.svc?xsd=xsd2"/&gt; &lt;/xsd:schema&gt; &lt;/wsdl:types&gt; -&lt;wsdl:message name="IService1_ksoapAdd_InputMessage"&gt; &lt;wsdl:part name="parameters" element="tns:ksoapAdd"/&gt; &lt;/wsdl:message&gt; -&lt;wsdl:message name="IService1_ksoapAdd_OutputMessage"&gt; &lt;wsdl:part name="parameters" element="tns:ksoapAddResponse"/&gt; &lt;/wsdl:message&gt; -&lt;wsdl:message name="IService1_addParam_InputMessage"&gt; &lt;wsdl:part name="parameters" element="tns:addParam"/&gt; &lt;/wsdl:message&gt; -&lt;wsdl:message name="IService1_addParam_OutputMessage"&gt; &lt;wsdl:part name="parameters" element="tns:addParamResponse"/&gt; &lt;/wsdl:message&gt; -&lt;wsdl:portType name="IService1"&gt; -&lt;wsdl:operation name="ksoapAdd"&gt; &lt;wsdl:input message="tns:IService1_ksoapAdd_InputMessage" wsaw:Action="http://tempuri.org/IService1/ksoapAdd"/&gt; &lt;wsdl:output message="tns:IService1_ksoapAdd_OutputMessage" wsaw:Action="http://tempuri.org/IService1/ksoapAddResponse"/&gt; &lt;/wsdl:operation&gt; -&lt;wsdl:operation name="addParam"&gt; &lt;wsdl:input message="tns:IService1_addParam_InputMessage" wsaw:Action="http://tempuri.org/IService1/addParam"/&gt; &lt;wsdl:output message="tns:IService1_addParam_OutputMessage" wsaw:Action="http://tempuri.org/IService1/addParamResponse"/&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:portType&gt; -&lt;wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1"&gt; &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt; -&lt;wsdl:operation name="InsertUserDetails"&gt; &lt;soap:operation style="document" -&lt;wsdl:operation name="ksoapAdd"&gt; &lt;soap:operation style="document" soapAction="http://tempuri.org/IService1/ksoapAdd"/&gt; -&lt;wsdl:input&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:input&gt; -&lt;wsdl:output&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; -&lt;wsdl:operation name="addParam"&gt; &lt;soap:operation style="document" soapAction="http://tempuri.org/IService1/addParam"/&gt; -&lt;wsdl:input&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:input&gt; -&lt;wsdl:output&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:binding&gt; -&lt;wsdl:service name="Service1"&gt; -&lt;wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1"&gt; &lt;soap:address location="http://localhost:51086/Service1.svc"/&gt; &lt;/wsdl:port&gt; &lt;/wsdl:service&gt; &lt;/wsdl:definitions&gt; </code></pre> <p>this is my xsd2:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; -&lt;xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/InsertIntoUserWCF" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.datacontract.org/2004/07/InsertIntoUserWCF" elementFormDefault="qualified"&gt; -&lt;xs:complexType name="testadd"&gt; -&lt;xs:sequence&gt; &lt;xs:element name="number_1" type="xs:int" minOccurs="0"/&gt; &lt;xs:element name="number_2" type="xs:int" minOccurs="0"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:element name="testadd" type="tns:testadd" nillable="true"/&gt; &lt;/xs:schema&gt; </code></pre> <p>here is my soap request:</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;ksoapAdd xmlns="http://tempuri.org/" id="o0" c:root="1"&gt; &lt;n0:num1 xmlns:n0="http://tempuri.org/"&gt; &lt;number_1&gt;25&lt;/number_1&gt; &lt;number_2&gt;25&lt;/number_2&gt; &lt;/n0:num1&gt; &lt;/ksoapAdd&gt; &lt;/v:Body&gt; &lt;/v:Envelope&gt; </code></pre> <p>soap response:</p> <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;s:Body&gt; &lt;ksoapAddResponse xmlns="http://tempuri.org/"&gt; &lt;ksoapAddResult&gt;0&lt;/ksoapAddResult&gt; &lt;/ksoapAddResponse&gt; &lt;/s:Body&gt; &lt;/s:Envelope&gt; </code></pre> <p>this is my java code using ksoap2:</p> <pre><code>private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = "http://10.0.2.2:51086/Service1.svc?wsdl"; private static final String SOAP_ACTION4 = "http://tempuri.org/IService1/ksoapAdd"; private static final String METHOD_NAME4 = "ksoapAdd"; private static final String SOAP_ACTION5 = "http://tempuri.org/IService1/addParam"; private static final String METHOD_NAME5 = "addParam"; try { testadd numX = new testadd(25,25); SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME4); PropertyInfo prop = new PropertyInfo(); prop.setNamespace(NAMESPACE); prop.setName("num1"); prop.setType(numX.getClass()); prop.setValue(numX); Request.addProperty(prop); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(Request); envelope.implicitTypes = true; HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.debug=true; androidHttpTransport.call(SOAP_ACTION4, envelope); Log.d(logtag + " request dump", androidHttpTransport.requestDump); Log.d(logtag + " response dump", androidHttpTransport.responseDump); final SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); final int num = Integer.parseInt(response.toString()); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>this is my java class testadd:</p> <pre><code>import java.util.Hashtable; import org.ksoap2.serialization.KvmSerializable; import org.ksoap2.serialization.PropertyInfo; public class testadd implements KvmSerializable{ int number1; int number2; testadd(){} testadd(int a, int b){ number1 = a; number2 = b;} @Override public Object getProperty(int arg0) { switch(arg0) { case 0: return number1; case 1: return number2; } return null; } @Override public int getPropertyCount() { return 2; } @Override public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { switch(arg0) { case 0: arg2.type = PropertyInfo.INTEGER_CLASS; arg2.name = "number_1"; break; case 1: arg2.type = PropertyInfo.INTEGER_CLASS; arg2.name = "number_2"; break; default:break; } } @Override public void setProperty(int arg0, Object value) { switch(arg0) { case 0: number1 = Integer.parseInt(value.toString()); break; case 1: number2 = Integer.parseInt(value.toString()); break; default: break; } } } </code></pre> <p>service code:</p> <pre><code>&lt;ServiceContract()&gt; _ Public Interface IService1 &lt;OperationContract()&gt; _ Function ksoapAdd(ByVal num1 As testadd) As Integer &lt;OperationContract()&gt; _ Function addParam(ByVal num1 As Integer, ByVal num2 As Integer) As Integer End Interface &lt;DataContract()&gt; _ Public Class testadd Private number1 As Integer Private number2 As Integer &lt;DataMember()&gt; _ Public Property number_1() As Integer Get Return number1 End Get Set(ByVal value As Integer) number1 = value End Set End Property &lt;DataMember()&gt; _ Public Property number_2() As Integer Get Return number2 End Get Set(ByVal value As Integer) number2 = value End Set End Property End Class </code></pre> <p>service methods:</p> <pre><code>Public Function ksoapAdd(ByVal num1 As testadd) As Integer Implements IService1.ksoapAdd MsgBox(num1.number_1) Return num1.number_1 + num1.number_2 End Function Public Function addParam(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Implements IService1.addParam MsgBox(num1 + num2) Return num1 + num2 End Function </code></pre> <p>I know this is a lot of code, but it think its necessary to understand the whole picture.</p> <p>Thank you!</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.
 

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