gpt4 book ai didi

android - 使用 KSoap 从 Android 连接到 Web 服务

转载 作者:行者123 更新时间:2023-11-30 04:16:16 27 4
gpt4 key购买 nike

我是安卓新手。我需要从 android 连接到 web 服务。 webservice 方法返回一个大于 10MB 的字符串值。我想尝试使用 KSOAP。有人可以给我一个使用 KSOAP 从 android 连接到 SOAP 网络服务的简短示例吗?

最佳答案

添加KSOAP jar文件并为webservice使用Async方法

  public class Connection extends AsyncTask<Void,Void,Void> {
@Override
protected Void doInBackground(Void... params) {
String SOAP_ACTION = "http://www.example.com/Get/GetCount";
String METHOD_NAME = "GetCount";
String NAMESPACE = "http://www.example.com";
String URL = "http://www.example.com/Get.php?wsdl";
String Result;
SoapObject request1 = new SoapObject(NAMESPACE, METHOD_NAME );
request1.addProperty("AppId", 1);
SoapSerializationEnvelope envelope = new soapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; envelope.setOutputSoapObject(request1);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true; try {
//this is the actual part that will call the webservice
androidHttpTransport.call(soapaction, envelope);
}
catch (IOException e) {
e.printStackTrace(); }
catch (XmlPullParserException e)
{ e.printStackTrace(); }
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
Result = result.getProperty(0).toString();
JSONObject jArray = new JSONObject(Result);
JSONArray Count = jArray.getJSONArray("Details");

ArrayList<HashMap<String, String>> myList = new ArrayList<HashMap<String, String>>();
for(int i=0;i < Count .length();i++){

HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = Count .getJSONObject(i);
map.put("id", e.getString("ID"));
myList.add(map);
}

关于android - 使用 KSoap 从 Android 连接到 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938836/

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