![]() |
Help needed in processing a web service response Hi, I am a beginner in BlackBerry development. I am trying to call a web service and process the response. I am successfully able to call the web service but I have trouble parsing the response. Can you please help me in deciphering what I am missing? It would do a world of good to me! Thanks in advance!! Here is the code i am using. Code: import net.rim.device.api.ui.UiApplication;Code: import java.util.Vector;Code: <?xml version="1.0" encoding="utf-8" ?> I can successfully use the getResult().toString() method to get the result and just display it. But I need to parse it as xml for processing complex return types as above. I appreciate any help as I have been breaking my head in this... Thanks in advance Regards, Karthik |
You can use the DOM API or the SAX Parser. For DOM, check the API docs for Document and DocumentBuilder. For SAX, check the API docs for SAXParser and related classes. There is also an example in the sample code that ships with the JDE. |
Hi Doug, Thanks a lot for your response. I totally forgot the option of using DOM / SAX. I used the following code to parse the XML response. But I get a class cast exception. Can you please check and let me know what is wrong with this. I would love to experiment and find it out, but the problem is that the simulator takes a lot of time to start in my machine and so it would be great if you could help me out. I cannot figure out what I am missing. Code: ht.call(soapAction, envelope);Edit: Given below is the exception I get and the string that follows after "[" is the output received by using envelope.getResponse().toString() -- truncated java.lang.ClassCastException [ anyType{Latiture=32.9659843;Longitude=96.74525;All ocationFactor=0.002192;FipsCode=48;PlaceName=Richa rdson;StateCode=TX;Details=anyType{WeatherData=any Type{Day=.... Regards, Karthik |
Can somebody help me with this? |
There isn't enough info here. How was envelope declared? What line of code causes the exception? |
Hi Doug, Thanks for your reply again. I have pasted the entire code and the exception i get is a class cast exception (java.lang.ClassCastException) whenever I am trying to parse the response using getResponse() method of the envelope as given below. I really don't know what I am missing. I have tried various means, but i have just hit a dead end. I tried to find some samples online but all of those examples receives the response, prints it using toString() and that's it! Is it uncommon to use web service calls in BB? I thought that as it doesn't have a good database support, most of BB applications will be using web services extensively. P.S - I have removed the links as BB Forums doesn't allow me to post the links Also the XML responses I receive are given above. Code: package com.rim.core.mobileedu;Thanks, Karthik |
Quote:
Example: //na.blackberry.com/eng/developers/javaappdev/javadevenv.jsp P.S. 'http' first, of course. |
Ok, one more thing I've just discovered. Try PHP Code: PHP Code: whereas second one does !? :shock: |
koic, you might want to try to find out what the class of the 2nd object is, so System.out.println(envelope.getResponse().getClass ().getName()); |
Thanks bemshaswing, that was the problem: envelope.getResponse() sometimes returns org.ksoap2.serialization.SoapPrimitive which cannot be cast to org.ksoap2.serialization.SoapObject, - they are on parallel branches :-o But bodyIn is org.ksoap2.serialization.SoapObject:idea: So does this solve the ClassCastException issue ? I'm afraid not, have to figure out what to do whith that SoapObject resurrected from bodyIn.... |
@bemshaswing and koic I was fed up with this method and chose to use another method to process the xml response and that's working. I will soon post the link that has a very good tutorial regarding this (I don't have the link stored in the m/c i am using right now) |
Well, the strange thing is that ksoap2 works only one way - serializes and sends soap to service. The problems come with response, - needs to be de-serialized. Recently I 'moved' to SAX parser, - works fine (y) |
| All times are GMT -5. The time now is 08:43 AM. |
Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.