Xmlparsing using Ksoap

1.1k views Asked by At

I am doing xmlparsing by using ksoap2. I had added ksoap2.jar file in my library.And done this coding

import java.io.IOException;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;

import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;


public class KsoapMidlet extends MIDlet {

Display display;
String strUserName= "Hello";
String strPassword = "World";
long ParentID;
String ChildIMEINumber;
String ChildName;
String serviceUrl = "http://www.semaphore.co.in/ChildTrackerService/ChildTrackerService.asmx";
String serviceNameSpace = "http://tempuri.org/";
String soapAction ="http://tempuri.org/AddChild";
String methodName = "AddChild";
Vector v=new Vector();



public void startApp() {
display = Display.getDisplay(this);
parsing();
// v.addElement("Hello");
// v.addElement("World");
// Constants d=new Constants();
// d.callSoap(methodName,v);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void parsing(){
SoapObject request = new SoapObject(serviceNameSpace,methodName);
request.addProperty("strUserName", strUserName);
request.addProperty("strPassword", strPassword);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.bodyOut = request;
envelope.encodingStyle = SoapSerializationEnvelope.ENC;
HttpTransport transport = new HttpTransport("http://www.semaphore.co.in/ChildTrackerService/ChildTrackerService.asmx");
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
transport.debug = true;
String result = null;

try {
transport.call("http://tempuri.org/" + methodName, envelope);
result = (envelope.getResponse()).toString();
System.out.println("***********************result********************************");
System.out.println("result=="+result);
System.out.println("Result :" + result.toString());
}
catch (org.xmlpull.v1.XmlPullParserException ex2) {
System.out.println("XmlPullParserException :" + ex2.toString());
System.out.println("Request \n" + transport.requestDump);
System.out.println("Response \n" + transport.responseDump);
} catch (SoapFault sf) {
System.out.println("SoapFault :" + sf.faultstring);
System.out.println("Request \n" + transport.requestDump);
System.out.println("Response \n" + transport.responseDump);
} catch (IOException ioe) {
System.out.println("IOException :" + ioe.toString());
System.out.println("Request \n" + transport.requestDump);
System.out.println("Response \n" + transport.responseDump);
}
}
}

But i am getting IO exception in line -----transport.call("http://tempuri.org/" + methodName, envelope);

The error mesage is:--

IOException :java.io.IOException: malformed header field <html>

Request <?xml version="1.0" encoding="UTF-8"?><v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><AddChild xmlns="http://tempuri.org/" id="o0" c:root="1"><strUserName i:type="d:string">Hello</strUserName><strPassword i:type="d:string">World</strPassword></AddChild></v:Body></v:Envelope>

Response

null
2

There are 2 answers

0
bpn On

I faced this same issue. The way i solved it was to change the profile settings on the phone. Go to the GPRS connection settings and change the protocol to HTTP (it was on WAP before).

1
Robert On

I assume that the HTTP response is an HTTP 404 with an custom HTML error page. That is the only possibility I could imagine how to get an in the web service answer.

May be your URL in transport.call(..) was wrong or the web-service on the server side was not active.

I would suggest to use a local http proxy like WebScarab (Java) or Fiddler (.Net) and redirect the calls to this local proxy. Then you will see what the server sends as response.