WCF 使用计算机名称而不是 IP 地址,无法解析

发布于 2024-11-26 23:45:32 字数 97 浏览 1 评论 0原文

我有一个 WCF 服务,可以在 LAN 上正常工作,但是当尝试从外部访问它时,服务引用失败。

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

余罪 2024-12-03 23:45:32

这对我有用。在配置文件中

< serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
< / system.serviceModel >

,如果它设置为 false,我就会得到疯狂的计算机名替换。

multipleSiteBindingsEnabled="true" 似乎是我需要做的所有事情才能正常工作。

This is what worked for me. In config file

< serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
< / system.serviceModel >

If it is set to false, I was getting that crazy computername substitution.

multipleSiteBindingsEnabled="true" seems to be all that I have to do for this to work as it should.

离不开的别离 2024-12-03 23:45:32

我正在研究一种重用 HTTP 请求中的 Host 标头的方法。在我看来,这应该适用于开发和生产。

事实证明很简单:

<behaviors>
    <serviceBehaviors>
       <behavior name="...">
         ...
         <useRequestHeadersForMetadataAddress />
       </behavior>
    </serviceBehaviors>
</behaviors>

这样,如果客户端可以访问 WSDL 端点,则可以确保可以使用相同的基本 url 访问所有关联的 wsdl/xsd 资源。

I was looking into an approach to reuse the Host header from HTTP request. In my opinion this should work in development as in production.

It turns out is as easy as:

<behaviors>
    <serviceBehaviors>
       <behavior name="...">
         ...
         <useRequestHeadersForMetadataAddress />
       </behavior>
    </serviceBehaviors>
</behaviors>

This way if the WSDL endpoint is accessible by a client this ensures that all the associated wsdl/xsd resources will be accessible with the same base url.

终止放荡 2024-12-03 23:45:32

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

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

<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 后) 。

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

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

4.)我发现的最佳解决方案是按照此处的“Timetheos”帖子实现 ServiceHosts Factory 属性:<一href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c7fd51a2-773e-41d4-95a0-244e925597fe" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c7fd51a2-773e-41d4-95a0-244e925597fe

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

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

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.) 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>

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.) If you have a domain name (www.myDomain.com) then add this to the host header in IIS.

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.) 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!

季末如歌 2024-12-03 23:45:32

您可以使用星号 *(通配符)代替基本 url 中的 LocalHost 或计算机名称,如下所示:

<add baseAddress="net.tcp://*:4502/WxWcfService_01" />

You can use an asterisk * (wildcard) in the place of LocalHost or machine name in the base url like so:

<add baseAddress="net.tcp://*:4502/WxWcfService_01" />
行雁书 2024-12-03 23:45:32

像这样设置服务端点和httpgeturl。

<services>
    <service behaviorConfiguration="serviceBehaviour" name="Demo.Service.MultiEndPointsService">
        <endpoint address="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic" binding="basicHttpBinding" bindingConfiguration="basicBinding"      contract="Demo.Service.MultiEndPointsService" />
    </service>
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="serviceBehaviour">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic"/>     
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
    </serviceBehaviors>
</behaviors>

Set service end point and httpgeturl like this.

<services>
    <service behaviorConfiguration="serviceBehaviour" name="Demo.Service.MultiEndPointsService">
        <endpoint address="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic" binding="basicHttpBinding" bindingConfiguration="basicBinding"      contract="Demo.Service.MultiEndPointsService" />
    </service>
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="serviceBehaviour">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic"/>     
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
    </serviceBehaviors>
</behaviors>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文