问题描述
- android客户端开发调用webservice是出现错误
-
HttpTransportSE对象se.call(null,envelope);不能执行,导致activity直接stop
class MyButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//调用方法int num1 = 1; int num2 = 2;
String wsdlUrl = "http://10.3.9.1:8080/TestPort/doAddPort";
String webMethod = "Add";
String nameSpace = "http://test.com/";
String soapAction = nameSpace+webMethod;SoapObject request = new SoapObject(nameSpace,webMethod); request.addProperty("a", num1); request.addProperty("b", num2); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = request; HttpTransportSE se = new HttpTransportSE(wsdlUrl); try { se.call(soapAction,envelope); System.out.println("你好 手机话费了快速点击封id是否"); if(envelope.getResponse()!= null){ Object result = envelope.getResponse(); Toast.makeText(MainActivity.this, "结果为:"+result, 2).show(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
se.call(soapAction,envelope);里面写null或者soapAction都输不出“你好 手机话费了快速点击封id是否”
解决方案
第一最好能在子线程中调用se.call(soapAction,envelope);
第二可能是因为你的开发环境没有搭好,
第三可能是你没有加入网络应用权限
第四在MainIFest.xml中要取消对SDK版本的限制规定
具体可以参考我的博客
http://blog.csdn.net/qhrqhrqhr/article/details/32461007
时间: 2024-10-10 10:01:39