random4Infinity
random4Infinity

Reputation: 193

Getting ksoap object from HttpTransportSE.responseDump

I am clueless how to proceed further while converting transport.responseDump which returns string(xml data in string form) to ksoap object. May be some code snippet will help me in describing my problem:

synchronized (transportLockObject)
        {
            transport.debug = true;            
            String soapAction = TARGET_NAMESPACE+"/"+method;

            try {
                transport.call(soapAction, envelope);
            } catch (SSLHandshakeException she) {
                she.printStackTrace();          
            }
        }
         System.out.println("Response ----------"+transport.responseDump);

This is how I am getting the responseDump. I am saving this dump so that it can be used later (say when I don't want actual online data for testing purpose or no connection[whatever]). Later what normally I do is

        Object response = envelope.getResponse();

        //Check if response is available... if yes parse the response
        if (response != null)
        {
            if (myResponse != null)
            {
                myResponse.parse(response);
            }
        }

This response which I passed in parse() is actually a soap object. Can Any body tell how can I convert my value returned from transport.responseDump into soap object, so that I can pass it into parse() method?

Any clue or link will be helpful. any help will be appreciated.

Upvotes: 2

Views: 1249

Answers (1)

naveejr
naveejr

Reputation: 735

You can use "bodyIn" instead of 'getResponse'

after

httpTransport.call(SOAP_ACTION, soapEnvelope);

Use

SoapObject result = (SoapObject) soapEnvelope.bodyIn;
UserDefined resultVariable = new UserDefined(j);

The UserDefined constructor should be able to handle this.

If your expected object is a user defined object you should implement that with kvmserializable. you can find some example here.

KSoap2 and KvmSerializable - How to Send complex Objects like Stringarrays

Upvotes: 1

Related Questions