【问题标题】:Having trouble connecting to wcf service on localhost from Android emulator从 Android 模拟器连接到本地主机上的 wcf 服务时遇到问题
【发布时间】:2013-10-06 18:19:54
【问题描述】:

我正在使用 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 构建和部署。 对我可能做错的事情有什么建议吗? :)

【问题讨论】:

标签: c# android wcf iis iis-express


【解决方案1】:

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

【讨论】:

  • 我也为我的网络服务的 ip 解决了更改的 localhost。谢谢:)
  • 我从没想过这会奏效。但是我怎么知道呢?
  • 是你电脑的这个ip还是安卓模拟器?你在哪里改变它?谢谢
  • 当时我会假设我的电脑。有点模糊,因为这篇文章大约是。 4 岁:/
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-13
  • 2019-12-23
  • 2014-10-15
相关资源
最近更新 更多