我正在尝试从网络服务获得回复。但是我收到了一些异常错误:主要是这个
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服务的方法,而webservice应该返回两个字符串(比如说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)方法。我应该从webservice获得两个字符串,但我不能使用带有SoapPrimitive的getProperty(index)。 所有建议表示赞赏 谢谢
答案 0 :(得分:0)
我不确定这是你需要的确切解决方案,但这对我有用,我之前遇到了同样的问题,但是需要5个参数,我只是使用SoapObject添加了3个参数,所以它给出了这种类型的错误,所以在调用此webservice之前,请确保使用 request.addProperty(“test”,“test”)添加了所有必需参数。