gpt4 book ai didi

android - 在 android 中调用 soap 请求时出错?

转载 作者:行者123 更新时间:2023-11-30 03:00:56 25 4
gpt4 key购买 nike

我在我的 android 应用程序中使用 Ksoap2 android assembly 2.4。我尝试使用 soap 调用 Web 服务。但是我在 transport.call(soapAction, envelop) 处收到错误消息;这条线。
日志:

org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}soap:Fault>@1:301 in java.io.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);




}

上面是我的代码,请给我一个解决方案。

最佳答案

这是一个例子。使用此代码

 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>

关于android - 在 android 中调用 soap 请求时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22550602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com