Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Contributor
madusha_nir
Posts: 4
Registered: ‎06-02-2011
My Carrier: Student

working with ksoap2 SoapObjects

Hi,

I'm using ksoap2 to connect to a .NET webservice from the BB application. I was doing fine until I came across handling multiple outputs from the web service. So its  great if someone can help

 

This is the part of coding in the BB application

 

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);         envelope.setOutputSoapObject(rpc);       
envelope.bodyOut = rpc;       
envelope.dotNet = true;       
envelope.encodingStyle = SoapSerializationEnvelope.XSD;                     
HttpTransport ht = new HttpTransport(serviceUrl);     
ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");       
ht.debug = true;
try{
ht.call(soapAction, envelope);
SoapObject body = (SoapObject)envelope.bodyIn;
}

 

 

and the SOAP responce looks like following

 

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  <soap:Body>   

<GetSewPTPResponse xmlns="http://tempuri.org/">     

<GetSewPTPResult>       

<SewPTP>         

<BuyerName> string </BuyerName>         

<PTP> string </PTP>     

  </SewPTP>       

<SewPTP>         

<BuyerName>string</BuyerName>         

<PTP>string</PTP>       

</SewPTP>     

</GetSewPTPResult>   

</GetSewPTPResponse> 

</soap:Body></soap:Envelope>

 

What i want to do is get BuyerNames and PTP value separately. this way the property count is 1 and when i print the output it displays all the values in the database table with tag names of the above xml as one continous string.

 

I'm stuck here, pls help.thanks in advance :smileyhappy:

 

 

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Carrier: none

Re: working with ksoap2 SoapObjects

Hi madusha_nir,

   ksoap2 response is in Json format. so u can use json classes and retrive the values.

USE THIS IN THE CLASS

result =  envelope.getResponse().toString();

 

AND u will get this output i think so.

eg:{"BuyerName":"_name","PTP":"_ptp"}

 

pass the result in this method and retrive the values.

 

public String GetSewPTPResultJson(String result){
        String message = "";
        try {
           JSONObject jsonObject = new JSONObject(result);

            if (jsonObject != null) {

                String  _buyerName = jsonObject .get("BuyerName").toString());

                String  _ptp = jsonObject .get("PTP").toString());

            }
        } catch (JSONException e) {
        }
    }

 

Thanks & Regards

             pp

 

Please use plain text.
New Contributor
madusha_nir
Posts: 4
Registered: ‎06-02-2011
My Carrier: Student

Re: working with ksoap2 SoapObjects

hi pp,

thanks a lot for the response. I tried the ur suggestion, but it doesnt seem to work because i get the output in the following format.

 

GetSewPTPResponse{GetSewPTPResult=anyType{SewPTP=anyType{BuyerName=aaa;PTP=90;};{SewPTP=anyType{BuyerName=bbb;PTP=80;};..................};}

 

and the other problem is that im stuck to BB api 5.0, according to the requirement.:Helpsmilie:any idea???

thanks.

 

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Carrier: none

Re: working with ksoap2 SoapObjects

Hi ,

   This result is of type array and  you  can use json array. But the response dont have any [].

http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Implementing-JSON-in-your-applic...

http://208.74.204.192/t5/Java-Development/How-do-I-parse-this-json/m-p/398574

http://code.google.com/p/json-simple/wiki/EncodingExamples

 

check these three links. we have retrieved multiple outputs by providing arguments.

 

GetSewPTPResponse{GetSewPTPResult=anyType:[{SewPTP=anyType{BuyerName=aaa;PTP=90;};              

                                                                                                {SewPTP=anyType{BuyerName=bbb;PTP=80;};

                                                                                                {                          ----"-----                                           ;}

                                                                                                ]

                                          };

}

 

here [ ] represents array.

 

Thanks & Regards

               pp

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Carrier: none

Re: working with ksoap2 SoapObjects

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Carrier: none

Re: working with ksoap2 SoapObjects

Hi,
sorry once again, i have not done with this kind of out put because we got everything in json format but the one u have sent is not json. I have searched many threads and they all have mentied like U have to Make your custom Method.

And in this method you have to use String function like indexOf() and Split. and get the required value.

http://supportforums.blackberry.com/t5/Java-Development/how-to-parse-values-using-ksoap/td-p/613707

http://supportforums.blackberry.com/t5/Java-Development/How-to-parse-results-from-a-KSOAP2-web-servi...


Thanks & Regards
pp


Please use plain text.
New Contributor
madusha_nir
Posts: 4
Registered: ‎06-02-2011
My Carrier: Student

Re: working with ksoap2 SoapObjects

hi,

thanks a LOT for the support. I wonder why the format is different from default json format. Nothing special is done about the format of the ksoap response in my program.

 

I developed a custom method to separate the values, but it makes the application slow because in that way each char in the response has to be checked separately. anyway, ill follow the links.

 

Thanks & Best Regards.

Please use plain text.