在android中调用soap请求时出错?
我在我的android应用程序中使用Ksoap2 android assembly 2.4。我试图使用soap调用web服务。但我在transport.call(soapAction,envelope)中遇到错误;这行。在android中调用soap请求时出错?,android,soap,android-ksoap2,Android,Soap,Android Ksoap2,我在我的android应用程序中使用Ksoap2 android assembly 2.4。我试图使用soap调用web服务。但我在transport.call(soapAction,envelope)中遇到错误;这行。 日志: org.xmlpull.v1.XmlPullParserException:应为:END_标记{http://schemas.xmlsoap.org/soap/envelope/}主体(位置:java.io中的END_标记@1:301)。InputStreamReade
日志:
org.xmlpull.v1.XmlPullParserException:应为:END_标记{http://schemas.xmlsoap.org/soap/envelope/}主体(位置:java.io中的END_标记@1:301)。InputStreamReader@41743310)
我的代码是:
String url = "http://192.168.56.1:8080/CxfWebservice/webservices/Calculator";
// String namespace = "http://localhost:8080/wsdl";
String namespace = "http://192.160.59.1:8080/wsdl";
String methodname = "sum";
public static void SoapOperation(String url, String method_name,
String name_space) throws Exception {
String soapAction = name_space + method_name;
SoapObject request = new SoapObject(name_space, method_name);
PropertyInfo p = new PropertyInfo();
p.setName("arg0");
p.setValue(5);
p.setType(Integer.TYPE);
PropertyInfo p1 = new PropertyInfo();
p1.setName("arg1");
p1.setValue(15);
p1.setType(Integer.TYPE);
request.addProperty(p );
request.addProperty(p1);
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelop.setOutputSoapObject(request);
envelop.dotNet = true;
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
transport.call(soapAction, envelop);
String xml = transport.responseDump;
System.out.println("the response xml is:"+xml);
}
stringurl=”http://192.168.56.1:8080/CxfWebservice/webservices/Calculator";
//字符串命名空间=”http://localhost:8080/wsdl";
字符串命名空间=”http://192.160.59.1:8080/wsdl";
String methodname=“sum”;
公共静态void SoapOperation(字符串url、字符串方法名称、,
字符串名称(U空格)引发异常{
字符串soapAction=名称\空格+方法\名称;
SoapObject请求=新的SoapObject(名称\空间、方法\名称);
PropertyInfo p=新的PropertyInfo();
p、 集合名(“arg0”);
p、 设定值(5);
p、 setType(Integer.TYPE);
PropertyInfo p1=新的PropertyInfo();
p1.集合名(“arg1”);
p1.设定值(15);
p1.setType(Integer.TYPE);
请求。添加属性(p);
请求。添加属性(p1);
SoapSerializationEnvelope信封=新的SoapSerializationEnvelope信封(
第11版);
Envelope.setOutputSoapObject(请求);
envelope.dotNet=true;
HttpTransportSE传输=新的HttpTransportSE(url);
transport.debug=true;
transport.setXmlVersionTag(“”);
运输呼叫(soapAction,信封);
字符串xml=transport.responseDump;
System.out.println(“响应xml为:“+xml”);
}
以上是我的代码,请给我一个解决方案。这里是一个示例。使用此代码
public void InteractWithWebService() {
try {
final String URL = con.getResources().getString(R.string.URL);
final String NameSpace = con.getResources().getString(
R.string.NAMESPACE);
final String MethodName = "sum";
final String SOAP_ACTION = con.getResources().getString(
R.string.SOAP_ACTION)
+ MethodName;
SoapObject Request = new SoapObject(NameSpace, MethodName);
Request.addProperty("param_name", Object_name.getText().toString()
.trim());
Request.addProperty("param_name", Object_name.getText().toString()
.trim());
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htp = new HttpTransportSE(URL);
htp.call(SOAP_ACTION, soapEnvelop);
// SoapObject response;
SoapPrimitive resultString = (SoapPrimitive) soapEnvelop
.getResponse();
if (resultString != null) {
status = Integer.parseInt(resultString.toString());
}
} catch (Exception ex) {
status = -1;
}
}
在字符串文件中添加这些行
<string name="NAMESPACE">http://tempuri.org/</string>
<string name="URL">http://Your_Localhost_address/Name_of_Service.svc</string>
<string name="SOAP_ACTION">http://tempuri.org/IName_of_Service/</string>
http://tempuri.org/
http://Your_Localhost_address/Name_of_Service.svc
http://tempuri.org/IName_of_Service/
您使用的是什么绑定?我使用了与您上面提到的相同的代码,但出现了相同的错误。
<string name="NAMESPACE">http://tempuri.org/</string>
<string name="URL">http://Your_Localhost_address/Name_of_Service.svc</string>
<string name="SOAP_ACTION">http://tempuri.org/IName_of_Service/</string>