WCF 正在使用计算机名而不是 IP 地址并且无法解析 [英] WCF is using the computer name instead of the IP address and cannot be resolved

查看:21
本文介绍了WCF 正在使用计算机名而不是 IP 地址并且无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 服务在 LAN 上运行良好,但是当尝试从服务引用外部访问它时失败.

I have a WCF service that works fine on the LAN but when trying to access it from outside the service reference fails.

我的 WCF 服务托管在使用静态 IP 无域的 win2k3 机器上.

My WCF service is hosted on a win2k3 box that is using a static IP no domain.

推荐答案

经过一番挖掘,我找到了这个问题的答案 - 这是我发现的,希望它可以为其他人节省一些时间和麻烦.

I found an answer to this after some digging - here is what I have found hopefully it can save someone else some time and bother.

1.) 将 IP 添加到端点地址 &添加带有基本 IP 地址的主机名,如下所示:

1.) Add the IP to the endpoint address & add a host name with the base IP address like so:

<endpoint
  address="http://xx.xx.xx.xx/ServiceApp/Service.svc"
  binding="basicHttpBinding" contract="IService">
</endpoint>
<host>
  <baseAddresses>
    <add baseAddress="http://xx.xx.xx.xx/ServiceApp/" />
  </baseAddresses>
</host>

这曾经足以让我的服务参考工作,但迪斯科文件开始返回计算机名称而不是 ip(我认为这是在更新到 .NET 4.0 之后).

This used to be enough to make my service reference work but the disco file started being returned with the computer name instead of the ip (I think this was after updating to .NET 4.0).

2.) 如果您有域名 (www.myDomain.com),请将其添加到 IIS 中的主机标头中.

2.) If you have a domain name (www.myDomain.com) then add this to the host header in IIS.

3.) 添加 IP 地址 &计算机名称到客户端主机文件(简单的修复并不总是可以让您的所有客户端将其添加到他们的主机文件中)

3.) Add the IP address & computer name to the clients hosts file (easy fix not always possible to get all of your clients to add this to their host file however)

4.) 我发现的最佳解决方案是按照此处的Timetheos"帖子实现 ServiceHosts 工厂属性:http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c7fd51a2-773e-41d4-947a02544

4.) The BEST SOLUTION I found was to implement the ServiceHosts Factory Attribute as per "Timetheos" post here: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c7fd51a2-773e-41d4-95a0-244e925597fe

这对我来说效果很好,因为我可以测试开发 &在本地调试我的服务库,然后使用服务应用程序将服务部署到我的开发服务器,发布后无需更改任何配置文件.

This worked well for me as I could test develop & debug my service library locally and then use a service app to deploy the service to my dev server and didn't have to change any configuration files after publishing it.

这整个过程完全是一场噩梦,我不希望任何人发生这种情况,所以如果您处于相同的情况并且需要有关上述几点的更多信息,请联系!

This whole process was a total nightmare, and I wouldnt wish it upon anyone so if you are in the same situation and need anymore info on the above points just get in touch!

这篇关于WCF 正在使用计算机名而不是 IP 地址并且无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆