2012-01-11 38 views
1

我是android开发新手,我需要使用SOAP消息从Web服务中获取XML文件。我已经尝试了我的级别来找出Android中的SOAP消息解析,但是,我无法找到解析SOAP消息的确切解决方案。这里我附上了我的示例代码来解析SOAP消息。你能帮我解析Android中的SOAP消息吗? (响应权限被拒绝)。如何在android中访问Webservice?

我试过如下代码:

SoapObject request = new SoapObject(NAMESPACE ,METHOD_NAME); 
request.addProperty("username","d"); 
request.addProperty("password","d123"); 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet=true; 
envelope.setOutputSoapObject(request);envelope.setAddAdornments(true); 
HttpTransportSE httpTransport = new HttpTransportSE(URL);   
try 
 { 
    httpTransport.call(SOAP_ACTION, envelope); //send request 
     SoapObject result=(SoapObject)envelope.bodyIn; 
     String results = result.toString(); 
     tv.setText(""+results); 
 } 
 catch (Exception e) 
 { 
      tv.setText(e.getMessage()); 
  } 

AndroidManifest.Xml file: 

<uses-permission android:name="android.permission.INTERNET"> 
</uses-permission> 
+0

是REST不是一种选择,还要确保你这样做在后台线程中分离到类似的主UI线程我解释了另一个问题,我昨天在这里回答http://stackoverflow.com/questions/8812281/android-emulator-crash-if-click-while-processing/8812798#8812798 – 2012-01-11 10:23:05

回答

1

你在你的代码所缺少envelope.getResponse();,prabably可以是你没有得到响应的原因。

你可以试试,

SoapObject result=(SoapObject)envelope.getResponse(); 
String results = result.toString(); 
+0

谢谢你,但回复是同样的权限被拒绝 – 2012-01-11 11:24:40

+0

发布问题中的例外。 – 2012-01-11 11:25:47

0

你可以像下面这样做

 HttpPost httppost = new HttpPost(webServicePath); 
    httppost.setHeader("Content-Type", "text/xml;charset=UTF-8"); 

    HttpParams params = new BasicHttpParams(); 
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, 
      HttpVersion.HTTP_1_1); 

    String soapRequestXML = getXMLAsString(); 
    soapRequestXML = prepareInputParam(soapRequestXML); 

    StringEntity se; 
    se = new StringEntity(soapRequestXML, HTTP.UTF_8); 
    se.setContentType("text/xml"); 
    httppost.setEntity(se); 

    response = httpClient.execute(httppost); 
+0

感谢您的回复。 – 2012-01-13 04:56:50