首先导入 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();
}
}