Android WSDL Web Service ksoap2

后端 未结 1 1488
说谎
说谎 2020-12-04 03:51

I am trying to connect to a web service via an Android device by using the ksoap2 library. I\'ve gotten it to work on two different services fine, but now I\'ve ran into a

相关标签:
1条回答
  • 2020-12-04 04:13

    I had similar problems in the past. I'll give you an example of a part i had to fix in my application and how i did, check if you did these steps in your case:
    In the wsdl there was:

    <message name="invokeService">
         <part name="serviceName" type="xsd:string"/>
         <part name="documents" type="tns:uriList"/>
         <part name="literalDocs" type="ns1:stringArray"/>
         <part name="connID" type="xsd:long"/>
         <part name="gateParams" type="tns:gateRuntimeParameterArray"/>
         <part name="userCtx" type="tns:userContext"/>
    </message>
    


    So I had to follow these steps:
    1- check if your classes implementing KvmSerializable are accurately defined and not missing anything (this is cruciale for complex types)

    2-Add ALL the necessary soap object properties that you need, for example in my case :

    //for the part: <part name="serviceName" type="xsd:string"/>
    SoapObject.addProperty("serviceName", whateverServiceNameItWas);
    
    //for the part: <part name="documents" type="tns:uriList"/>,where uriList was a complex type
    PropertyInfo pi = new PropertyInfo();
    pi.setName("documents");
    pi.setValue(usrOptPr.getDocuments());
    pi.setType(UriList.class);
    sobj.addProperty(pi);
    

    etc... 3-Build the enveloppe:

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.setOutputSoapObject(SoapObject);
    

    4- Add mappings between complex types(ie local class that implement kvmserializable, and the real matching classes on the web service)

    //---------------------------------------------------------------------------------------
    // MAPPINGS:
    // A mapping tells the ksoap what class to generate.
    // Complex data types that are not mapped are generated as SoapObjects.
    // The mapping is required for both the request and the response.
     //---------------------------------------------------------------------------------------
    
    //for example the UriList above     
    soapEnvelope.addMapping(theNamespace, UriList.class.getSimpleName(), UriList.class);
    

    5- Add marshalling:(Marshalling uses java serialization to change Objects to stream of data to be unmarshalled on the web service.)

    Marshal floatMarshal = new MarshalFloat();
    floatMarshal.register(soapEnvelope);
    

    6- Use AndroidHttpTransport to call the web service
    UPDATE
    I also noticed that you have in the browser request:

    <d4p1:Schools i:nil="true" />
    

    While in Android:

    <Schools i:type="d:string"></Schools>
    

    Sometimes ksoap2 bugs with such a scenario, i had the same case so what i did is i just removed (commented out, since it allows nil ie null values) this param (ie schools) from its specific class that implements kvmserializable ( of course you will have to modify other stuff in the class like "getPropertyCount" and "getPropertyInfo" to adapt to this change). When i did that it worked, so try that and let me know.

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