2011-02-08 59 views
2

我正在使用kso​​ap2进行xml解析。我又增加了ksoap2.jar文件在我library.And做这个编码使用Ksoap进行Xml解析

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); 
} 
} 
} 

但我正在逐渐IO例外线----- transport.call("http://tempuri.org/" + methodName, envelope);

错误mesage是: -

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

请求 < ?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>

响应

null 

回答

1

我假设HTTP响应是一个带有自定义HTML错误页面的HTTP 404。这是我可以想象如何获得Web服务答案的唯一可能性。

可能是您在transport.call(..)中的URL错误,或者服务器端的Web服务未激活。

我建议使用WebScarab(Java)或Fiddler(.Net)等本地http代理,并将调用重定向到本地代理。然后你会看到服务器作为响应发送了什么。

+0

@罗伯特感谢您的答复,我得到了它的解决方案。这是因为我的设备中的代理设置。 – 2011-07-28 04:50:03

2

我面临同样的问题。我解决它的方式是更改手机上的配置文件设置。转到GPRS连接设置并将协议更改为HTTP(它之前位于WAP上)。

+0

感谢您的回复。 – 2011-07-28 04:50:18