无法从Android模拟器连接到localhost上的wcf服务

时间:2013-10-06 18:19:54

标签: c# android wcf iis iis-express

我正在使用Xamarin Studio构建一个应该访问wcf服务的应用程序。使用以下网址从我的浏览器访问该服务正常工作: http://localhost:52277/api

每当我尝试从我的Android代码访问它时,我都会遇到以下异常:

System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Exception: Connection refused
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
  at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
  at ServiceStack.ServiceClient.Web.ServiceClientBase.Send[String] (System.String httpMethod, System.String relativeOrAbsoluteUrl, System.Object request) [0x00051] in c:\Users\nicklas.winger\Documents\GitHub\ServiceStack\src\ServiceStack.Common\ServiceClient.Web\ServiceClientBase.cs:896

我正在IIS Express上运行该服务,并且我已经修改了我的iis applicationhost.config(根据有关复数的一门课程,从bindingInformation中删除'localhost'):

<site name="ProteinTrackerMvc" id="45">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="c:\users\nicklas.winger\documents\visual studio 2012\Projects\ProteinTrackerMvc\ProteinTrackerMvc" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:52277:" />
    </bindings>
</site>

此外,我的Web服务正在使用iis express在上述端口进行构建和部署。 对我可能做错的任何建议? :)

1 个答案:

答案 0 :(得分:5)

使用以下ip解决: 10.0.2.2而不是localhost。