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

后端 未结 1 461
粉色の甜心
粉色の甜心 2020-12-06 08:01

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 whe

相关标签:
1条回答
  • 2020-12-06 08:19

    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!!

    0 讨论(0)
提交回复
热议问题