今天在使用webservice调用接口的时候出现一个问题就是,连接服务器成功但是感觉参数总是没传过去。比如我做一个请求获取号码归属地的请求。使用webservice建立请求,因为设置envelope.dotNet = false;这个值不对,导致返回结果永远是手机号码不对,其实不是手机号码不对,只是因为后台服务使用.net开发的所以这个值必须设置为true。
相关请求的代码如下:
private void webServiceRequest() { // soapobject构建 String nameSpace = "http://WebXml.com.cn/"; String serviceMethod = "getMobileCodeInfo"; String serviceURL = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"; String soapAction = "http://WebXml.com.cn/getMobileCodeInfo"; SoapObject request = new SoapObject(nameSpace, serviceMethod); // 指定WebService的命名空间和调用的方法名 request.addProperty("mobileCode", "18672740522"); request.addProperty("userID", ""); Log.e("lwc", "count = " + request.getPropertyCount()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.bodyOut = request; envelope.dotNet = true; envelope.setOutputSoapObject(request); // Android传输对象 HttpTransportSE transport = new HttpTransportSE(serviceURL); transport.debug = true; try { transport.call(soapAction, envelope); // 获取返回的数据 SoapObject object = (SoapObject) envelope.bodyIn; // 获取返回的结果 String result = object.getProperty(0).toString(); Log.e("lwc", "result = " + result); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } }
<p>版权声明:本文为博主原创文章,未经博主允许不得转载。</p>