如何在android中发送soap请求?
我是 WSDL webservices 的新手,使用 KSoap2 库在 android 中调用 wsdl webservices 。
这是我的肥皂请求转储,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:loy="http://loyalcard.com/LoyalCardWebService/">;
<soapenv:Header/>
<soapenv:Body>
<loy:GetOffersByLocation>
<!--Optional:-->
<loy:Location>
<!--Optional:-->
<loy:Latitude>?</loy:Latitude>
<!--Optional:-->
<loy:Longitude>?</loy:Longitude>
</loy:Location>
</loy:GetOffersByLocation>
</soapenv:Body>
</soapenv:Envelope>
我传递这个 SopaObject 的方式如下:
PropertyInfo latitude = new PropertyInfo();
latitude.name="Latitude";
latitude.type=Double.class;
latitude.setValue(32.806673);
PropertyInfo longitude = new PropertyInfo();
longitude.name="Longitude";
longitude.type=Double.class;
longitude.setValue(-86.791133);
SoapObject results = null;
String methodName = "OffersByLocation";
String actionName = "http://loyalcard.com/LoyalCardWebService/GetOffersByLocation";
SoapObject request = new SoapObject(NAMESPACE,methodName);
request.addProperty(latitude);
request.addProperty(longitude);
这里将纬度和经度值直接传递给 OffersByLocation ,我应该传递元素 Location 。请任何人帮助如何通过 Location 传递参数。
我已经尝试过上述过程,但收到错误消息,
06-17 11:52:55.934: WARN/System.err(350): SoapFault - faultcode: 'soapenv:Server' faultstring: 'org.apache.axis2.databinding.ADBException: Unexpected subelement Latitude' faultactor: 'null' detail: org.kxml2.kdom.Node@44f6ddc0
请任何人告诉我如何在 Soap 对象中传递上述肥皂请求转储?
问候, 斯里尼瓦斯
I am new to WSDL webservices , using KSoap2 library to call wsdl webservices in android .
This is my soap request dump
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:loy="http://loyalcard.com/LoyalCardWebService/">;
<soapenv:Header/>
<soapenv:Body>
<loy:GetOffersByLocation>
<!--Optional:-->
<loy:Location>
<!--Optional:-->
<loy:Latitude>?</loy:Latitude>
<!--Optional:-->
<loy:Longitude>?</loy:Longitude>
</loy:Location>
</loy:GetOffersByLocation>
</soapenv:Body>
</soapenv:Envelope>
I am passing this SopaObject like :
PropertyInfo latitude = new PropertyInfo();
latitude.name="Latitude";
latitude.type=Double.class;
latitude.setValue(32.806673);
PropertyInfo longitude = new PropertyInfo();
longitude.name="Longitude";
longitude.type=Double.class;
longitude.setValue(-86.791133);
SoapObject results = null;
String methodName = "OffersByLocation";
String actionName = "http://loyalcard.com/LoyalCardWebService/GetOffersByLocation";
SoapObject request = new SoapObject(NAMESPACE,methodName);
request.addProperty(latitude);
request.addProperty(longitude);
Here am passing latitude and longitude values directly to OffersByLocation , I should pass through element Location . Please can any one help how to pass parameters through Location .
I have tried with above procedure but am getting error saying
06-17 11:52:55.934: WARN/System.err(350): SoapFault - faultcode: 'soapenv:Server' faultstring: 'org.apache.axis2.databinding.ADBException: Unexpected subelement Latitude' faultactor: 'null' detail: org.kxml2.kdom.Node@44f6ddc0
Please can any one tell me how to pass above soap Request dump in Soap Object ?
Regards,
Srinivas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以手动构造请求XML,并将其发送到kSOAP进行发送和响应处理。您可以使用soapUI编写请求XML,然后使用诸如
{%key%}
之类的关键字将它们保存在res/raw
中,其中应在运行时放置参数。以下是替换关键字的代码:
要使用 kSOAP 发送自定义 XML 请求,您需要创建自己的 Transport 类。
或者您可以使用
DefaultHttpClient
手动发送请求(请参阅在 Android 上使用客户端/服务器证书进行双向身份验证 SSL 套接字),并使用 kSOAP只是为了解析响应。You can also manually construct the request XML, and send it to kSOAP for sending and response processing. You can write your request XML using soapUI, then save them in
res/raw
with keywords like{%key%}
where parameters should be placed at runtime.Here is the code for replacing the keywords:
To send custom XML request with kSOAP you need to make your own Transport class.
Or you can send the request manually using
DefaultHttpClient
(see Using client/server certificates for two way authentication SSL socket on Android), and use kSOAP just for parsing the response.您必须创建自己的 xml 生成器类才能做到这一点。我也在使用相同的程序。反编译 ksoap2 库并研究它们如何生成并根据您的需要更改它。
You have to make your own xml generator class to do that. I am also using the same procedure. decompile the ksoap2 library and study the how they generate and change it as you required..
你可以像这样使用。
我希望这可以帮助你
谢谢,
柴塔尼亚
You can use like this.
I hope this may help u
Thanks,
Chaitanya