• android 调用wcf skyCc


    package com.ahzyt.activity.webservice;

    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.util.List;
    import java.util.Map;

    import com.ahzyt.activity.R.string;
    import com.ahzyty.AhzyProgressDialog;

    import android.content.Context;
    import android.content.SharedPreferences;
    import android.net.ConnectivityManager;
    import android.net.NetworkInfo;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.text.TextUtils;
    import android.util.Log;
    import android.view.View;

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;
    import org.ksoap2.transport.HttpsTransportSE;
    import org.xmlpull.v1.XmlPullParserException;
    import java.net.Proxy.Type;

    public class WebServiceConnetionUtil extends Thread {
     public static final int CANCEL = 4;
     // public static final int ERROR = 3;
     // public static final int NO_NETWORK = 2;
     // public static final int SUCCESS = 1;
     // private static final int TIMEOUT = 30000;
     // private static final int WEBSERVICE_STATES_NO_NETWORK = 2;
     // private static final int WEBSERVICE_STATES_SUCESS = 1;
    // private final static String METHOD_NAME = "doService";
    // // private final String METHOD_PARAMNAME = "request";
     
     private final static String METHOD_NAME = "doScanCode";
     // private final String METHOD_PARAMNAME = "request";
     private final static String NAMESPACE = "http://tempuri.org/";
     // private String URL = "WS/FISService.asmx";
     private static String ServiceUrl = "http://192.168.1.101:84/ZY.Service/app-AssetMgrService";
         private static String action="http://tempuri.org/IAssetMgr/doScanCode";
     // private Map<String, String> attrMap;
     private Context context;
     private Handler handle = null;
     private HttpTransportSE httpTransportSE;
     private boolean isCancel = false;
     // private List<WebServiceRequestNode> nodeList;
      private AhzyProgressDialog progressDialog = null;
       private static String response;
      private static String safeParam;
     //
     
      public WebServiceConnetionUtil(Handler paramHandler, Context paramContext,String paramresponse) {
      
       this.safeParam= paramresponse;
       this.handle=paramHandler;
       this.context=paramContext;
      }

     
     public static int  getSafeAreaCodeInFo() {

      HttpTransportSE httpTransportSE = new HttpTransportSE(ServiceUrl);
      // new HttpsTransportSE(
      // android.net.Proxy.getDefaultHost(), android.net.Proxy
      // .getDefaultPort(), ServiceUrl, 3000);

      Log.e("cc", "host:" + android.net.Proxy.getDefaultHost());
      Log.e("cc", "port:" + android.net.Proxy.getDefaultPort());
      httpTransportSE.debug = true;
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
    //  SoapObject soapObject = new SoapObject("NAMESPACE",
    //    "doService");
    //  String str2 = "<request cmd='searchAreaByCode' safearea_code='"
    //    + safeParam + "' />";
      
      SoapObject soapObject = new SoapObject("http://tempuri.org/" ,
        "doScanCode");
             String str2 =safeParam;
      soapObject.addProperty("request", str2);
      envelope.bodyOut = soapObject;
      envelope.dotNet = true;
      try {
       //httpTransportSE.call("http://ws.ahzytx.com.cn/doService", envelope);
       
      httpTransportSE.call("http://tempuri.org/IAssetMgr/doScanCode", envelope);
       SoapObject resultObject = (SoapObject) envelope.bodyIn;
           response = envelope.getResponse().toString();
       Log.e("AhzyFis", "" + response);
         int i = 1;
               return i;
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (XmlPullParserException e) {

       e.printStackTrace();
      }
      return 0;
     }


     @Override
     public void run() {
      super.run();
      Bundle localBundle;
      Message localMessage2;
      try {
       int i=getSafeAreaCodeInFo();
       Message localMessage1;
       if (this.isCancel) {
        localMessage1 = this.handle.obtainMessage();
        localBundle = new Bundle();
        localMessage1.what = 4;
        localMessage1.setData(localBundle);
        this.handle.sendMessage(localMessage1);
       }
       while (true)
       {
                     localMessage1 = this.handle.obtainMessage();
               localBundle = new Bundle();
               localMessage1.what = 1;
               localBundle.putString("response", this.response);
               localMessage1.setData(localBundle);
               this.handle.sendMessage(localMessage1);
        return;
       }
      } catch (Exception localException) {
       localException.printStackTrace();
       localMessage2 = this.handle.obtainMessage();
       localBundle = new Bundle();
       if (this.isCancel);
        
      }
      
     }

     public void doStart() {

      this.progressDialog = new AhzyProgressDialog(this.context);
      this.isCancel = false;
      this.progressDialog.setCancelButton(new View.OnClickListener() {
       public void onClick(View paramView) {
        if (WebServiceConnetionUtil.this.httpTransportSE != null)
         ;
        try {
         Log
           .d("AhzyFis",
             "begin httpTransportSE.getConnection().disconnect().");
         // WebServiceConnetionUtil.this.httpTransportSE.getConnection().disconnect();//断开连接
         Log
           .d("AhzyFis",
             "finish httpTransportSE.getConnection().disconnect().");
         WebServiceConnetionUtil.this.isCancel = true;
         WebServiceConnetionUtil.this.progressDialog.cancel();
         return;
        } catch (Exception localIOException) {
         while (true)
          localIOException.printStackTrace();
        }
       }
      });
      this.progressDialog.setCancelable(false);
      this.progressDialog.show();
      start();

     }
    }

  • 相关阅读:
    模块和包
    网络基础之网络协议
    计算机硬件知识
    面试题集锦(一)
    二分查找法
    ORM多表操作示例
    Django之URL(路由系统)用法
    用Nginx实现微信小程序本地SSL请求
    [PHP7.0-PHP7.2]的新特性和新变更
    利用Node的chokidar 监听文件改变的文件。
  • 原文地址:https://www.cnblogs.com/cmzcheng/p/android.html
Copyright © 2020-2023  润新知