• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

kSOAP tutorial

 
Michael Yuan
author
Ranch Hand
Posts: 1427
 
Moldovan John
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm trying to use kSOAP 1.2 with J2ME for a school project and I also use your article.
I created a MIDlet and I defined a method to parse a SOAP
message (it's something easy, just for testing):

public void parseString()
{
String msg = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://www.w3.org/2001/12/soap- envelope\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-ins tance\" " +"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"& gt;" +
"<SOAP-ENV:Body>" +
"<result>" +
"<message xsi:type=\"xsd:string\">Hello World</message>" +
"</result>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
try
{
ByteArrayInputStream is = new ByteArrayInputStream(msg.getBytes());
InputStreamReader isr = new InputStreamReader(is);
XmlParser parser = new XmlParser(isr);
SoapEnvelope envelope = new SoapEnvelope();//new ClassMap(Soap.VER12));
envelope.parse(parser);
String body = (String)envelope.getBody();
String result = (String)envelope.getResult(); System.out.println("Body="+body+";Result="+result );
}
catch(Exception e)
{
e.printStackTrace();
}
}

When I run this example, I get the following exception:

org.kxml.io.ParseException: unexpected: StartTag <Envelope> line: -1 attr: [] @-1:-1
at org.kxml.parser.AbstractXmlParser.read(+53)
at org.ksoap.SoapEnvelope.parseHead(+19)
at org.ksoap.SoapEnvelope.parse(+5)
at Main.parseString(+50)
at Main.startApp(+4)
at javax.microedition.midlet.MIDletProxy.startApp(+7 )
at com.sun.midp.midlet.Scheduler.schedule(+225)
at com.sun.midp.dev.DevMIDletSuiteImpl.schedule(+7)
at com.sun.midp.Main.runLocalClass(+20)
at com.sun.midp.Main.main(+68)


If create the SoapEnvelope object like this:
SoapEnvelope envelope = new SoapEnvelope(new ClassMap(Soap.VER12));
I get a ClassCastException.
I would appreciate any kind of help.
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic