2011-08-14 126 views
3

我想從使用kso​​ap庫的Android客戶端調用Web服務。無法從Android客戶端調用C#.net Web服務方法

這裏是我的Android代碼

private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; 
private static final String METHOD_NAME = "HelloWorld"; 
private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL = "http://192.16.0.230/WebService/Test.asmx"; 
TextView tv; 

public void call() 
{ 
    try { 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     request.addProperty("name", "zawoad"); 

     SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet=true; 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

     androidHttpTransport.call(SOAP_ACTION, envelope); 

     String result = (String)envelope.getResponse(); 

     tv.setText(result); 
    } catch (Exception e) { 
     tv.setText("exception :" + e.getLocalizedMessage()); 
     } 
} 

,這裏是這是寫在Test.asmx我的web服務方法文件

[WebMethod] 
public string HelloWorld(string name) 
{ 
    return "Hello World" + name; 
} 

在執行androidHttpTransport.call(SOAP_ACTION, envelope);線,它拋出以下異常

org.xmlpull.v1.XmlPullParserException:expected:START_TAG {http://schemas.xmlsoap.org/so AP /信封/}信封(位置:START_TAG @ 2:44 [email protected]

請幫助..

回答

0

您正在執行不會發生調用。 什麼是Web服務返回類型?我們可以傳遞這些值並稱之爲。

2

這是工作代碼

private static final String SOAP_ACTION = "http://tempuri.org"; 
private static final String METHOD_NAME = "HelloWorld"; 
private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL = "http://192.16.0.230/WebService/Test.asmx?wsdl"; 
/*write ?wsdl only for local system testing*/ 

TextView tv; 

public void call() 
{ 
    try { 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     request.addProperty("name", "zawoad"); 

     SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet=true; 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,20000);//Updated 

     androidHttpTransport.call(SOAP_ACTION, envelope); 
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse(); 
     String result = resultsRequestSOAP.toString(); 

     tv.setText(result); 
    } catch (Exception e) { 
     tv.setText("exception :" + e.getLocalizedMessage()); 
     } 
}