android調用.net wcf 服的方法

來源:互聯網
上載者:User

一、建立wcf服務

1 public class Service1 : IService12     {3         public string GetData(int value)4         {5             return string.Format("You entered: {0}", value);6         }7     }

web.config 檔案配置

 1 <services> 2       <service name="WcfSrv.Service1"> 3         <host> 4           <baseAddresses> 5             <add baseAddress = "http://localhost:8732/WcfSrv/Service1/" /> 6           </baseAddresses> 7         </host> 8         <endpoint address ="" binding="basicHttpBinding" contract="WcfSrv.IService1"> 9         </endpoint>10         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>11       </service>12     </services>

 

注意紅色部分為,預設的是wsHttpBinding ,這時android 調用wcf服務時會出現下面的異常
 org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@41308ae8)

然後把服務發布到原生iis中

二、android 調用wcf 服務

 1 static String SOAP_ACTION="http://tempuri.org/IService1/GetData";   2 private static final String NAMESPACE = "http://tempuri.org/";   3 private static String URL = http://10.0.2.2:8000/Service1.svc;   4 private static final String METHOD_NAME = "GetData";   5 SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME); 6 soapObject.addProperty("value", 33333); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 7 envelope.dotNet = true; 8 envelope.setOutputSoapObject(soapObject); 9 String xmlMessage = "";10 try {11   HttpTransportSE transport = new HttpTransportSE(URL); 12   transport.call(SOAP_ACTION, envelope);13   SoapObject sb = (SoapObject) envelope.bodyIn;14   xmlMessage = sb.toString(); } catch (IOException e) {15   e.printStackTrace();16 } catch (XmlPullParserException e) {17   e.printStackTrace();18 }19 return xmlMessage;

 

 

 

聯繫我們

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