2011-02-08 2 views
2

ksoap2를 사용하여 xmlparsing을 수행하고 있습니다. 나는이 코드를 수행 내 저 도서관에 ksoap2.jar 파일을 추가했다 ----- transport.call("http://tempuri.org/" + methodName, envelope);Ksoap을 사용한 Xml 구문 분석

오류 메세지를 지정하지 않고는하지만 라인에서 IO 예외를 얻고있다

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

: -

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라고 가정합니다. 그것이 웹 서비스 대답을 얻는 방법을 상상할 수있는 유일한 가능성입니다.

transport.call (..)의 URL이 잘못되었거나 서버 측의 웹 서비스가 활성화되지 않았을 수 있습니다.

WebScarab (Java) 또는 Fiddler (.Net)와 같은 로컬 http 프록시를 사용하고이 로컬 프록시에 대한 호출을 리디렉션 할 것을 제안합니다. 그러면 서버가 응답으로 보내는 것을 볼 수 있습니다.

+0

@ Robert 답장을 보내 주셔서 감사합니다. 해결책을 찾았습니다. 내 기기에서 프록시 설정 때문이었습니다. –

2

나는이 동일한 문제에 직면했다. 내가 해결 한 방법은 전화의 프로필 설정을 변경하는 것이 었습니다. GPRS 연결 설정으로 가서 프로토콜을 HTTP로 변경하십시오 (이전에는 WAP에있었습니다).

+0

답장을 보내 주셔서 감사합니다. –