View Single Post
Old 06-08-2009, 11:47 PM   #6 (permalink)
karthik25
New Member
 
Join Date: May 2009
Location: Dallas, TX
Model: 8900
PIN: N/A
Carrier: Simulator
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;

import javax.xml.parsers.SAXParser;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.ksoap2.*;
import org.kxml2.kdom.Element;
import org.w3c.dom.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParser;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.xml.jaxp.XMLParser;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

import net.rim.device.api.xml.parsers.*;
 
public class TestScreen extends MainScreen implements FieldChangeListener {
	PictureBackgroundButtonField _pButton;
	LabelField lblInfo;

	public TestScreen(){
		_pButton = new PictureBackgroundButtonField("study",Field.FOCUSABLE,"study.png");
        _pButton.setChangeListener(this);
		add(_pButton);
		
		add(new SeparatorField());
		
		lblInfo = new LabelField("");
		add(lblInfo);
	}
	
    public void fieldChanged(Field field, int context) 
    {

        String text = "";
        
        if (field instanceof PictureBackgroundButtonField) {
            text = ((PictureBackgroundButtonField)field).getText();
        }
        
        Dialog.inform(text + " was clicked.");
        
        String serviceUrl = "";
    	String serviceNamespace = "";
    	String soapAction = "GetWeatherByZipCode";
    	String soapMethod = "GetWeatherByZipCode";

	String result = "";

	SoapObject rpc = new SoapObject(serviceNamespace, soapMethod);
	rpc.addProperty("ZipCode", "75080");

	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

	envelope.bodyOut = rpc;
	envelope.dotNet = true;
	envelope.encodingStyle = SoapSerializationEnvelope.XSD;

	HttpTransport ht = new HttpTransport(serviceUrl);
	ht.debug = true;

	String results_temp = "";
	
	try
	{
		ht.call(soapAction, envelope);
		
		SoapObject body = (SoapObject)envelope.getResponse();
		
		results_temp = (envelope.getResult()).toString();
		
		DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();			
		DocumentBuilder db=dbf.newDocumentBuilder();
		InputStream iStr =  (InputStream)envelope.bodyIn;
		Document dom = db.parse(iStr);
		
		org.w3c.dom.Element docFile = dom.getDocumentElement();
		docFile.normalize();
		
		org.w3c.dom.NodeList nl_name = docFile.getElementsByTagName("PlaceName");
		org.w3c.dom.Element nl_name_elem = (org.w3c.dom.Element) nl_name.item(0);
		String nl_name_value = nl_name_elem.getFirstChild().getNodeValue();
		result = nl_name_value;
	}
	catch(org.xmlpull.v1.XmlPullParserException ex2){
		ex2.printStackTrace();
	}
	catch(Exception ex){
		ex.printStackTrace();			
	}
	
	lblInfo.setText(result);
    }
}
Please help me resolve this problem, as it would do a world of good.

Thanks,
Karthik

Last edited by karthik25 : 06-08-2009 at 11:49 PM.
Offline   Reply With Quote