android soap webservers 无法执行 报错 ht.call(SOAP_ACTION, envelope);解决方法
2016-09-06 17:30
253 查看
1.可能没有加入网络访问权限,在Manifest里面加入,<uses-permission android:name="android.permission.INTERNET"/>
2.版本问题,很可能的问题,因为在android高于9的会出错,所以简单粗暴的办法就是,直接将版本信息
<uses-sdk
android:minSdkVersion="?"
android:targetSdkVersion="?"
/>
删除即可。
其他具体参考代码如下:
View Code
2.版本问题,很可能的问题,因为在android高于9的会出错,所以简单粗暴的办法就是,直接将版本信息
<uses-sdk
android:minSdkVersion="?"
android:targetSdkVersion="?"
/>
删除即可。
其他具体参考代码如下:
1 package com.example.soaptestforandroid; 2 3 import java.io.IOException; 4 5 import org.ksoap2.SoapEnvelope; 6 import org.ksoap2.serialization.SoapObject; 7 import org.ksoap2.serialization.SoapSerializationEnvelope; 8 import org.ksoap2.transport.HttpTransportSE; 9 import org.xmlpull.v1.XmlPullParserException; 10 11 import android.os.*; 12 import android.annotation.SuppressLint; 13 import android.app.Activity; 14 import android.util.Log; 15 import android.view.Menu; 16 import android.widget.*; 17 18 public class MainActivity extends Activity 19 { 20 21 private static final String SERVICE_NAMESPACE = "http://services.jason.com/"; 22 private static final String SERVICE_URL = "http://172.16.1.164:8080/MyWebServer/UserInfoPort?wsdl"; 23 private EditText tv = null; 24 25 26 27 @SuppressLint("NewApi") 28 @Override 29 protected void onCreate(Bundle savedInstanceState) 30 { 31 super.onCreate(savedInstanceState); 32 setContentView(R.layout.activity_main); 33 34 35 try { 36 tv = (EditText) findViewById(R.id.hello); 37 38 //如果本系统为4.0以上(Build.VERSION_CODES.ICE_CREAM_SANDWICH为android4.0) 39 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 40 // 详见StrictMode文档 41 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 42 .detectDiskReads().detectDiskWrites().detectNetwork() 43 .penaltyLog().build()); 44 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() 45 .detectLeakedSqlLiteObjects().detectLeakedClosableObjects() 46 .penaltyLog().penaltyDeath().build()); 47 } 48 49 // 调用的方法 50 String mathodName = "GetUserInfo"; 51 String SOAP_ACTION = SERVICE_NAMESPACE + mathodName; 52 // 创建HttpTransportSE对象 53 HttpTransportSE ht = new HttpTransportSE(SERVICE_URL); 54 55 ht.debug = true; 56 // 使用soap协议创建Envelop对象 57 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( 58 SoapEnvelope.VER10); 59 // 实例化SoapObject对象 60 SoapObject object = new SoapObject(SERVICE_NAMESPACE, mathodName); 61 // 将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息 62 envelope.bodyOut = object; 63 envelope.dotNet = true; 64 envelope.setOutputSoapObject(object); 65 // 调用webService 66 ht.call(SOAP_ACTION, envelope); 67 System.out.println("envelope.getResponse()---" 68 + envelope.getResponse()); 69 if (envelope.getResponse()!= null) { 70 71 SoapObject result = (SoapObject) envelope.bodyIn; 72 String name = result.getProperty(0).toString(); 73 System.out.println(name); 74 tv.setText("返回值为:" + name); 75 76 } else { 77 tv.setText("无返回值"); 78 } 79 } catch (Exception e) { 80 // TODO Auto-generated catch block 81 e.printStackTrace(); 82 } 83 84 } 85 86 @Override 87 public boolean onCreateOptionsMenu(Menu menu) 88 { 89 // Inflate the menu; this adds items to the action bar if it is present. 90 getMenuInflater().inflate(R.menu.main, menu); 91 return true; 92 } 93 94 }
View Code
相关文章推荐
- android soap webservers 无法执行 报错 ht.call(SOAP_ACTION, envelope);解决方法
- OS WebService的Soap请求无法获取参数的解决方法
- javaweb action无法跳转、表单无法跳转的解决方法
- android通过webView加载第三方h5应用,无法加载图片和播放视频的解决方法
- 关于Android原生集成5+webview,监听webview返回时,执行两次onkey方法问题的解决
- Android使用WebView无法定位问题的解决方法
- WebView中调用assets下的js脚本无法正常执行的解决方法
- 解决Android Webview 重定向无法 goback 的方法
- Android 中View仅仅能接收到ACTION_DOWN无法接收ACTION_MOVE和ACTION_UP解决的方法
- android4.2.2及以上webview调用java本地方法不执行解决办法
- ssh 项目中struts2 "input"返回后无法执行Action解决方法
- Android WebView无法加载本地html文件的解决方法
- 无法在WEB服务器上启动调试"解决方法大全
- ASP.NET配置(web.config)无法连接到SQL Server 数据库的解决方法
- ASP.NET配置(web.config)无法连接到SQL Server 数据库的解决方法
- ASP.NET-ASP.NET配置(web.config)无法连接到SQL Server 数据库的解决方法
- VMware Tools “无法计算本地文件大小。你可能没有执行该操作的权限。”的解决方法
- ora-12154 tns 无法处理服务名(执行的程序途径不一致导致,枚举网络数种方法,大家还有其他解决办法?)
- "无法在web服务器上调试的" 解决方法大全
- HTTP 错误 403.1 - 禁止访问:执行访问被拒绝。 解决方法该页无法显示