Android Ksoap wcf

 // 命名空间
 String serviceNameSpace = "http://tempuri.org/";

 String methodName = "GetAllPersons";
 // 请求URL
String serviceURL = "http://10.0.3.2:65458/WCFService2/Service.svc";
 //private static final String serviceURL = "http://10.14.4.67:3009/ITHmeApp/ITHomeService.asmx";
 // SoapAction
  String soapAction = "http://tempuri.org/IPersonService/GetAllPersons";
 //private static final String soapAction = "http://tempuri.org/ReceviceCommand";


 // 指定WebService的命名空间和调用的方法名
 SoapObject request = new SoapObject(serviceNameSpace, methodName);
 // example方法中有一个String的参数,这里将“android client”传递到example request.addProperty("i", "oh");
 request.addProperty("a","a1");
 request.addProperty("b1","b1");
 // 获得序列化的Envelope
 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
         SoapEnvelope.VER11);
 envelope.dotNet = true;
 envelope.bodyOut = request;

 // Android传输对象
 HttpTransportSE transport = new HttpTransportSE(serviceURL);
 transport.debug = true;

 // 调用WebService
 try {
     transport.call(soapAction, envelope);
 } catch (IOException e) {
     Log.d("KSOAP", e.toString());
 } catch (XmlPullParserException e) {
     Log.d("KSOAP", e.getMessage());
 }
 try {
     if (envelope.getResponse() != null) {
         Log.d("KSOAP", "go3: "+envelope.getResponse().toString()+envelope.toString());
     }
 } catch (SoapFault e) {
     Log.d("KSOAP", "error");
 }

你可能感兴趣的:(学习)