@Override
protected String doInBackground(Object... params) {
// 根据命名空间和方法得到SoapObject对象
SoapObject soapObject = new SoapObject(targetNameSpace, getSimpleProductByBarcode); // 命名空间就是WebService代码文件里的 [WebService(Namespace = "http://tempuri.org/")] 这个,最好不要用默认的
// 通过SOAP1.1协议得到envelop对象
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11); // 一定要确认版本,版本不对将报错
// 将soapObject对象设置为envelop对象,传出消息
envelop.dotNet = true;
envelop.setOutputSoapObject(soapObject);
// 或者envelop.bodyOut = soapObject;
// 设置参数
soapObject.addProperty("barcode", params[0]);
HttpTransportSE httpSE = new HttpTransportSE(WSDL);
// 开始调用远程方法
try {
httpSE.call(targetNameSpace + getSimpleProductByBarcode, envelop);
// 得到远程方法返回的SOAP对象
// 如果以SoapObject来转换发生错误,就要试着以SoapPrimitive来转换
SoapPrimitive resultObj = (SoapPrimitive) envelop.getResponse();
if (resultObj != null)
scan_result = String.valueOf(resultObj.toString());
} catch (IOException e) {
e.printStackTrace();
return "IOException";
} catch (XmlPullParserException e) {
e.printStackTrace();
return "XmlPullParserException";
}
return "success";
}