passing objects to wcf soap service from android using ksoap2; it sends and receives 0

馋奶兔 提交于 2019-11-27 23:12:56

I finally got it to work!

Turns out my android ksoap2 code didn't like the default namespace(tempuri.org) set by WCF in the SOAP service.

My guess is that with the default namespace, the request envelop was unable to map the passed testadd object to the datacontract in which the testadd class is defined in the service. By defining a namespace explicitly to the servicecontract and datacontract in the WCF service, this changes/rearranges the wsdl and makes the datacontract accessible.

I followed this tutorial to get rid of the tempuri.org namespace- http://blogs.msdn.com/b/endpoint/archive/2011/05/12/how-to-eliminate-tempuri-org-from-your-service-wsdl.aspx

I added the following in the appropriate places in the service code (VB)

<ServiceContract(Namespace:="http://wcfservicetest.org/Service1")> _
<DataContract(Namespace:="http://wcfservicetest.org/Service1")> _
<ServiceBehavior(Namespace:="http://wcfservicetest.org/Service1")> _

I changed my namespace to "http://wcfservicetest.org/Service1" and edited NAMESPACE and SOAP_ACTION in the android java code with the new namespace.

After doing this I got the result I wanted!

Here is the soap request:

<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/">
<v:Header />
<v:Body>
<ksoapAdd xmlns="http://wcfservicetest.org/Service1" id="o0" c:root="1">
<n0:num1 xmlns:n0="http://wcfservicetest.org/Service1">
<number_1>25</number_1>
<number_2>25</number_2>
</n0:num1>
</ksoapAdd>
</v:Body>
</v:Envelope>

soap response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ksoapAddResponse xmlns="http://wcfservicetest.org/Service1">
<ksoapAddResult>50</ksoapAddResult>
</ksoapAddResponse>
</s:Body>
</s:Envelope>

So my advice to anyone else learning SOAP services with ksoap2, do no use the default namespace, set your own namespace. I wasted a week trying to figure this out.

Hope this helps someone someday!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!