使用 Android 调用 SOAP Web 服务的最佳方式是什么?
我需要一些建议。 我有一个 WSDL
,我需要调用一些服务。
对于您来说,使用 Android 调用 SOAP Web 服务
的最佳方式是什么? 我知道我们可以:
- 使用库
Ksoap 2
- 创建
xml
模板并通过简单的http 协议
发送它们。 - 或者我可以做类似的事情:
public class AppelService {
private static final String NAMESPACE = "http://my-website.com";
private static final String URL = "http://mon-example-web-services/wsdl.WSDL";
private static final String SOAP_ACTION = "getWeather";
private static final String METHOD_NAME = "getWeather";
private String getWeather(String city) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("city", city);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
Log.e("getWeather", "", e);
}
}
}
根据您自己的经验,您认为最好的方法是什么?
任何帮助表示赞赏。 谢谢。
I need some advices.
I've a WSDL
and I need to call some services.
For you, What is the best way to callSOAP web service
with Android?
I know that we can:
- use the library
Ksoap 2
- create
xml
templates and send them by a simplehttp protocol
. - Or i can do something like:
public class AppelService {
private static final String NAMESPACE = "http://my-website.com"; private static final String URL = "http://mon-example-web-services/wsdl.WSDL"; private static final String SOAP_ACTION = "getWeather"; private static final String METHOD_NAME = "getWeather"; private String getWeather(String city) { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("city", city); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); androidHttpTransport.call(SOAP_ACTION, envelope); } catch (Exception e) { Log.e("getWeather", "", e); } } }From your own experience, what do you think is the best way to do it ?
any help is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我绝对提倡使用 ksoap2-android libary。我已经做了这项研究,就多功能性而言,没有什么比使用这个库更好的了。
您提供的代码是 ksoap2。
来自 ksoap2-android 网站:
I would definitely advocate using ksoap2-android libary. I have done this very research, and nothing beats using this library in terms of versatility.
The code you have provided is ksoap2.
From the ksoap2-android website:
我个人使用 ksoap2-android 因为它对于解析响应对象非常简单......
如果您对此感到满意,为什么还要使用其他东西?
A bientôt ;)
编辑:我的意思当然是 ksoap2 -android
I personally use ksoap2-android because it is pretty straightforward for parsing response object...
If you are comfortable with it, ,why would you use something else ?
A bientôt ;)
Edit : I mean ksoap2 -android of course