Android WSDL Web Service ksoap2

后端 未结 1 1507
说谎
说谎 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:

    
         
         
         
         
         
         
    
    


    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: 
    SoapObject.addProperty("serviceName", whateverServiceNameItWas);
    
    //for the part: ,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:

    
    

    While in Android:

    
    

    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)
提交回复
热议问题