作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是安卓新手。我需要从 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/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!