2

This might be easy one , but I am not able to figure out what is going wrong.

I have used KSOAP2 library to call SOAP web services.

I am trying to parse XML response using simple XML framework as string -

    //call web service
    HttpTransportSE httpTransport = new HttpTransportSE(_soapURL);
    httpTransport.debug = true;
    httpTransport.call(_soapAction, _soapEnvelope);

    //get the dump and pass for serialization
    Serializer serializer = new Persister();
    serializer.read(modelObject, httpTransport.responseDump);

Then I try to print the value -

    Log.d(TAG, "@@@ Parse Response : " + modelObject.getWSInitializeResult());

which gives me null instead of somestring

My sample KSOAP response is -

   <?xml version="1.0" encoding="utf-8"?>
   <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema">

       <soap:Header>
          <CSSoapResponseHeader xmlns="http://webservice.test.com/">
               <CSProtocolVersion>v1.0</CSProtocolVersion>
               <Status>0</Status>
          </CSSoapResponseHeader>
       </soap:Header>

       <soap:Body>
          <WSInitializeResponse xmlns="http://webservice.test.com/">
                <WSInitializeResult>somestring</WSInitializeResult>
           </WSInitializeResponse>
       </soap:Body>
    </soap:Envelope>

My Model class is -

     @Root(strict = false, name = "Envelope" )//tried with  name = "soap:Envelope"
     @NamespaceList({
         @Namespace(reference = "http://www.w3.org/2003/05/soap-envelope", prefix = "soap"),
         @Namespace(reference = "http://www.w3.org/2001/XMLSchema-instance", prefix = "xsi"),
         @Namespace(reference = "http://www.w3.org/2001/XMLSchema", prefix = "xsd"),
      })
      public class WSInitializeResponse extends BaseResponse {

             @Path("soap:Envelope/soap:Body/WSInitializeResponse/")//tried with @Path("Envelope/Body/WSInitializeResponse/")
             @Namespace(reference = "http://webservice.test.com/")
             @Element
             private String WSInitializeResult;

             public String getWSInitializeResult() {
                   return WSInitializeResult;
             }

            public void setWSInitializeResult(String WSInitializeResult) {
                  this.WSInitializeResult = WSInitializeResult;
            }
      }

Please can any one help to fix the issue?

Thank in advance.

  • Better you model the soap by classes, see [here](http://stackoverflow.com/questions/24102741/simple-framework-skip-soap-envelope-and-body/24225297#24225297) and [here](http://stackoverflow.com/questions/13155056/deserialization-of-xml-with-simplexml-in-java/13193877#13193877) for some help. – ollo Sep 03 '15 at 20:40

0 Answers0