Android平台叫用.NET WebService詳解

來源:互聯網
上載者:User

Android調用.NET WebService 的注意事項!

網上有些資料說在需要傳入多個參數時,只要多個參數的順序與WSDL中參數出現的順序一致即可,名稱並不需要和WSDL中的一致,但實際測試發現,大多數情況下並不可行!)

// 調用的方法String methodName = "GetGoodsSet_Android";// 建立HttpTransportSE傳輸對象HttpTransportSE ht = new HttpTransportSE("http://192.168.1.115/Android_WebService/WebService1.asmx");ht.debug = true;// 執行個體化SoapObject對象SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);// 添加一個請求參數soapObject.addProperty("queryPara", queryPara);soapObject.addProperty("pagesze", PageSize);// 使用SOAP1.1協議建立Envelop對象SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);envelope.bodyOut = soapObject;// 設定與.Net提供的Web Service保持較好的相容性envelope.dotNet = true;try{// 調用Web Serviceht.call("http://tempuri.org/GetGoodsSet_Android", envelope);//Log.println(priority, tag, msg)if (envelope.getResponse() != null){// 擷取伺服器響應返回的SOAP訊息SoapObject result = (SoapObject)envelope.bodyIn;  //SoapPrimitive  result_P = (SoapPrimitive) envelope.getResponse();     //DialogUtil.showDialog(Main,WebServiceUtil.getCityListByProvince(), false);System.out.println(result.getAttributeCount());//SoapObject detail = (SoapObject) result.getProperty(methodName//+ "Result");// 解析伺服器響應的SOAP訊息。//return parseProvinceOrCity(detail);//SoapObject chileds =(SoapObject) result.getProperty(0);//SoapObject chiled_s =(SoapObject) chileds.getProperty(1);//JSONObject js_obj=new JSONObject(envelope.getResponse().toString());return envelope.getResponse().toString();}else{return "Null";}}catch (IOException e){e.printStackTrace();return e.getLocalizedMessage();}catch (XmlPullParserException e){e.printStackTrace();return e.getLocalizedMessage();}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.