android:ksoap2 org.xmlpull.v1.XmlPullParserException:预期:START_TAG异常
我正在尝试从网络服务获取响应。但是我遇到了一些异常错误:主要是这个错误
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) 方法与此处的结果一起使用。我应该从 webservice 获得两个字符串作为响应,但我不能将 getProperty(index) 与 SoapPrimitive 一起使用。 感谢所有建议 谢谢
I am trying to get a response from a web service. However I am getting some exception errors: mainly this one
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)
Actually I am trying to access a method of a web-service and the webservice is supposed to return two strings (Lets say String1 and String2). Moreover, I have to provide or pass two parameters (lets say Parameter 1 and Parameter 2 where Parameter 1 should be integer and Parameter 2 should be String) Here is my code
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();
}
}
}
Can anyone tell me if I am doing something wrong here.. Another very important question:
Can anyone tell me that why I can't use getProperty(0) or getProperty(1) method with the result here. I am supposed to get two strings in response from webservice but I can't use getProperty(index) with SoapPrimitive..
All suggestions are appreciated
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是您需要的确切解决方案,但这对我有用,我之前遇到过同样的问题,但是需要 5 个参数,我只是使用 SoapObject 添加了 3 个参数,所以它给出了这种类型的错误,所以请在调用此 Web 服务之前,请确保您已使用 request.addProperty("test","test") 添加了所有必需的参数。
I am not sure this is exact solution what you need but this works for me, I was getting same problem before, but There was 5 parameters needed and I just added 3 parameters using SoapObject, so it was giving this type of error, so please make sure that you have added all required parameters using request.addProperty("test","test") before call this webservice.