07-19-2011 01:07 AM
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 ![]()
07-19-2011 02:05 AM
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
07-19-2011 02:58 AM
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=a
and the other problem is that im stuck to BB api 5.0, according to the requirement.
any idea???
thanks.
07-19-2011 03:38 AM
Hi ,
This result is of type array and you can use json array. But the response dont have any [].
http://208.74.204.192/t5/Java-Development/How-do-I
http://code.google.com/p/json-simple/wiki/Encoding
check these three links. we have retrieved multiple outputs by providing arguments.
GetSewPTPResponse{GetSewPTPResult=anyType:[{SewPTP
};
}
here [ ] represents array.
Thanks & Regards
pp
07-19-2011 03:46 AM
07-19-2011 04:04 AM
07-19-2011 05:23 AM
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.