项目总结-访问WCFService

公司项目服务器是用.net写的,客户端需要调用WCFService,下面用代码说明下android怎么调用WCFService。

public class WebSoapUtil {

private static int timeOut = 10000; // 时限
private static HttpTransportSE androidHttpTransport = null;


public static SoapSerializationEnvelope getEnvelope(
SoapSerializationEnvelope envelope, String url, String soapAction,
SoapObject request, Context mContext) throws HttpResponseException,
IOException, XmlPullParserException {
if(!Tools.checkNetworkAvailable(mContext)){
return null;
}
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true; // 设置.net web service
envelope.headerOut = Tools.buildHeader(url, soapAction);
envelope.setOutputSoapObject(request);// 发送请求
// System.setProperty("http.keepAlive", "false");
androidHttpTransport = new HttpTransportSE(url, timeOut);
// androidHttpTransport.debug = true;
androidHttpTransport.call(soapAction, envelope);
if (envelope.getResponse() == null) {
System.out.println("请求服务器,连接成功但是数据存在问题");
envelope = null;// 连接成功但是数据是空值
}
return envelope;
}

上述文件是调用WCFService 缩写的工具类。调用的时候只需要传入相应参数就可以。

例如:

SoapObject request = new SoapObject(nameSpace, methodName);
request.addProperty("PatientId", PatientId);
request.addProperty("ClinicDate",ClinicDate);
envelope = WebSoapUtil.getEnvelope(envelope, url, soapAction, request, mContext);


你可能感兴趣的:(wcfservice)