android调用webservice

来源:互联网 发布:淘宝客服怎么知道业绩 编辑:程序博客网 时间:2024/05/16 08:43

首先导入 ksoap2-android-assembly-2.4-jar-with-dependencies.jar

 public static String queryRemoteInfor(String params) throws Exception{    String result = "";            String soapAction = "http://命名空间"+"调用方法名";// SOAP Action                    SoapObject rpc = new SoapObject("http://命名空间", "调用方法名");// 指定WebService的命名空间和调用的方法名    // 设置需调用WebService接口需要传入的参数    rpc.addProperty("param", params);        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(        SoapEnvelope.VER10);// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本    envelope.bodyOut = rpc;    envelope.setOutputSoapObject(rpc);    HttpTransportSE transport = new HttpTransportSE("http://xxxxx/cyservice/services/cyservice");//webservice如果是xife写的,就不要wsdl后缀  //  HttpTransportSE transport = SingletonHttpTransportSe.getInstance();    try {      transport.call(soapAction, envelope);      // 获取返回的数据        Object response = envelope.getResponse();      result = String.valueOf(response);      if (null == result ||result.equals("anyType{}") || result.equals("[]")) {        result="";      }      Log.i("webserviceeeeeeeee","成功");          return result;    } catch (Exception e) {      e.printStackTrace();      Log.i("webserviceeeeeeeee","失败");      throw new Exception();    }  }



0 0
原创粉丝点击