Android webService传输
作者:互联网
开发APP时,与C#项目对接时,使用webSerive进行数据传输
//接口的url
final String WSDL_URL = "http://" + ip +"/Service.asmx?wsdl";
//namespace 命名空间,我这里是默认的命名空间
final String namespace = "http://tempuri.org/";
//要调用的方法名称
final String methodName = "ServiceMessage";
// 创建HttpTransportSE对象
HttpTransportSE ht = new HttpTransportSE(WSDL_URL);
ht.debug = true;
SoapObject object = new SoapObject(namespace, methodName);
// 设置参数
object.addProperty("cmd", cmd);
object.addProperty("json", json);
// 使用soap1.1协议创建Envelop对象
// 实例化SoapObject对象
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(object);
String content = "";
try{
// 调用webService
ht.call(namespace + methodName, envelope);
if (envelope.bodyIn instanceof SoapFault){
// 如果返回的数据格式不是我们想要的,会进入这里
Log.e("===", JSON.toJSONString(envelope.bodyIn));
content = "";
} else {
//正常返回的数据
SoapObject result = (SoapObject) envelope.bodyIn;
content = result.getProperty(0).toString();
}
}catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
标签:methodName,webService,namespace,object,envelope,传输,Android,SoapObject,String 来源: https://blog.csdn.net/weixin_44288786/article/details/114878377