View Single Post
Old 03-06-2007, 05:21 AM   #2
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

i used ksoap for the webservice transaction then sax to parse the results, using this plugin for netbeans to create the class:

>>>netbeans 5.5 blackberry template

the code generated by the soap/sax template is:

package jhfisher.bclient;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import net.rim.device.api.xml.parsers.SAXParser;
import net.rim.device.api.xml.parsers.SAXParserFactory;
import org.ksoap.SoapFault;
import org.ksoap.SoapObject;
import org.ksoap.transport.HttpTransport;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/*
* testSoapSaxClass.java
*
* Created on March 6, 2007, 10:21 AM
* RIM Blackberry kSoap/Sax Class
*
* @author jfisher
*/


class testSoapSaxClass extends Thread{

String url = "";
String serverResponse = "";

public void run() {
try {
SoapObject RPC = new SoapObject("http://webservices.mycompany.net/module", "webservicename");
RPC.addProperty("parameterName", "");
serverResponse = "" + new HttpTransport(url, "http://webservices.mycompany.net/module/webservicename").call(RPC);
}catch (SoapFault sf){

}catch(Exception e){

}

try{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
InputStream in = new ByteArrayInputStream(serverResponse.getBytes());
InputSource inputSource = new InputSource(in);
saxParser.parse(in, new testSoapSaxClassHandler());
}catch(Exception ex){

}
}

static class testSoapSaxClassHandler extends DefaultHandler {
String builder;
String temp;

public void startDocument() throws SAXException {
}

public void startElement(String uri, String name, String qName, Attributes atts){
if ("".equals(uri)){
System.out.println("Start element: " + qName);
}
temp = "";
}

public void endElement(String uri, String name, String qName){
if ("".equals(uri)){
System.out.println("End element: " + qName);
}
}

public void characters(char buf[],int offset,int len) throws SAXException {
temp="";
String temp2;
temp2 = new String(buf, offset, len).trim();
if (!temp2.equals("") || !temp2.equals(" ")){
temp = temp2;
}else{
temp = "";
}
}

public void endDocument() throws SAXException {

}
}
}
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline