【发布时间】:2011-09-26 02:18:28
【问题描述】:
我正在尝试从 Web 服务获取响应。但是我遇到了一些异常错误:主要是这个
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@1:6 in java.io.InputStreamReader@40524b78)
实际上,我正在尝试访问 Web 服务的方法,并且该 Web 服务应该返回两个字符串(比如说 String1 和 String2)。此外,我必须提供或传递两个参数(假设参数 1 和参数 2,其中参数 1 应该是整数,参数 2 应该是字符串)这是我的代码
public class MyWebService extends Activity {
private static final String SOAP_ACTION ="http://www.mywebsite.com/myMethod";
private static final String METHOD_NAME = "MyMethod";
private static final String NAMESPACE = "http://www.myNamespace/";
private static final String URL = "http://mysession.com/myservice.asmx?WSDL";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("Parameter 1");
pi.setValue(1);
pi.setType(pi.INTEGER_CLASS);
request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("Parameter 2");
pi2.setValue("Any string");
pi2.setType(pi2.STRING_CLASS);
request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
//SoapObject result=(SoapObject)envelope.getResponse();
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
String resultData = result.toString();
//String string1=result.getProperty(0).toString();
//String string2=result.getProperty(1).toString();
Log.v("WEBSERVICE","RESPONSE: "+resultData);
} catch (Exception e) {
e.printStackTrace();
}
}
}
如果我在这里做错了什么,谁能告诉我。另一个非常重要的问题: 谁能告诉我为什么我不能在这里使用 getProperty(0) 或 getProperty(1) 方法的结果。我应该从 web 服务获得两个字符串作为响应,但我不能将 getProperty(index) 与 SoapPrimitive 一起使用。 感谢所有建议 谢谢
【问题讨论】:
-
首先将您的网址更改为
http://mysession.com/myservice.asmx。之后请检查您的SOAP_ACTION,METHOD_NAME和NAMESPACE是否正确,通常是SOAP_ACTION = NAMESPACE+METHOD_NAME。