android ksoap2調用.net Webservice 方法總結

來源:互聯網
上載者:User

ndroid  ksoap2調用.net Webservice 方法直接放到一個類裡:  

package com.util;    import org.ksoap2.SoapEnvelope;  import org.ksoap2.serialization.SoapObject;  import org.ksoap2.serialization.SoapSerializationEnvelope;  import org.ksoap2.transport.HttpTransportSE;        public class AsmxUtil   {      private String SOAP_ACTION = "";      private String NAMESPACE = "http://tempuri.org/";      private String METHOD_NAME = "";      private String ServiceURL = "";      SoapObject request =null;            public AsmxUtil(String serviceurl, String methodName)      {                    // 建立webservice連線物件            ServiceURL = serviceurl;          METHOD_NAME = methodName;          SOAP_ACTION = NAMESPACE + METHOD_NAME;          request = new SoapObject(NAMESPACE, METHOD_NAME);       }            public void AddProperty(String name, Object v)      {          //參數值          request.addProperty(name, v);              }            public String Call() throws Exception      {                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);          // soap協議版本必須用SoapEnvelope.VER11(Soap V1.1)           envelope.bodyOut = request;          envelope.dotNet=true;          //對dotnet webservice協議的支援,如果dotnet的webservice           //不指定rpc方式則用true否則要用false                     HttpTransportSE ht = new HttpTransportSE(ServiceURL);          ht.debug = true;          try {              ht.call(SOAP_ACTION, envelope);              if (envelope.getResponse() != null)               {                  String msg = envelope.getResponse().toString();                  return msg;              }               else               {                  return "error";              }          }          catch (Exception e) {              throw new Exception(e.getMessage());                }      }  }  調用方法:AsmxUtil au = new AsmxUtil("http://192.168.111.153/WebService2/Service1.asmx", "HelloWorld");      au.AddProperty("username","admin");au.AddProperty("password","123");        String xst = null;try {xst = au.Call();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();//text1.setText(e.getMessage());}

 

 Toast.makeText(this, xst, Toast.LENGTH_LONG).show();    

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.