【问题标题】:WCF (net.tcp) service: Works on all but one systemWCF (net.tcp) 服务:适用于除一个系统之外的所有系统
【发布时间】:2010-07-30 15:11:18
【问题描述】:

我已经在 Windows 服务中编写了一个 WCF 服务,但由于某种我无法弄清楚的原因,我将该服务部署在一堆系统上(在操作系统和配置上几乎完全相同),并且它可以在除了一台服务器。除了服务的基地址之外,所有部署的配置都是相同的。

服务启动时,打开ServiceHost没有异常,使用netstat -anp可以看到socket已经被服务进程打开了。我已经为丢弃的数据包设置了 Windows 防火墙日志记录,但日志文件仍然为空。

如果我尝试从 WCF 测试客户端访问 WCF 服务,我会收到以下消息:

Error: Cannot obtain Metadata from net.tcp://myhostname:9001/SysMonitorAgent 
If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error    
    URI: net.tcp://myhostname:9001/SysMonitorAgent    
    Metadata contains a reference that cannot be resolved: 'net.tcp://myhostname:9001/SysMonitorAgent'.
    There was no endpoint listening at net.tcp://myhostname:9001/SysMonitorAgent that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

我尝试过 WCF 日志记录,但甚至没有创建日志文件。

服务配置如下:

<system.serviceModel>
  <diagnostics>
    <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
  </diagnostics>
  <bindings>
    <netTcpBinding>
      <binding name="InterfaceServiceNetTcpBinding">
        <security mode="None">
          <transport clientCredentialType="None" protectionLevel="None" />
          <message clientCredentialType="None" />
        </security>
      </binding>
    </netTcpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior name="InterfaceServiceBehavior">
        <serviceMetadata httpGetEnabled="false" />
        <serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="SysMonitor.Agent.Interface.InterfaceService" behaviorConfiguration="InterfaceServiceBehavior">
      <endpoint address="" binding="netTcpBinding" bindingConfiguration="InterfaceServiceNetTcpBinding" contract="SysMonitor.Agent.Interface.IInterfaceService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://myhostname:9001/SysMonitorAgent" />
        </baseAddresses>
      </host>
    </service>
  </services>
</system.serviceModel>

我有点迷茫,因为没有任何迹象表明它为什么不起作用。任何帮助将不胜感激。

【问题讨论】:

    标签: c# wcf wcf-binding net.tcp wcftestclient


    【解决方案1】:

    在您正在部署的服务器上,是否也在端口 9100 上运行某些东西?

    好像找不到服务。您是否尝试过更改基地址?

    如果您将它部署在伺服系统上并且它在一台机器上不起作用,则通常是机器的配置。我会检查

    • .NET 版本
    • 确保此机器上没有设置防火墙来阻止绑定
    • 检查你要绑定的端口在本例中是打开的 9100
    • 如果需要,请确保任何第 3 方 .dll 都包含在 GAC 或文件夹中。
    • 验证所有 .dll 并且您的代码是最新的。

    我看到错误消息说“net.tcp://myhostname:9001/SysMonitorAgent”

    您是否尝试将其替换为机器 IP 地址而不是使用主机名?

    【讨论】:

    • 我已检查该端口是否仅由正确的进程使用。 .NET 是第 4 版,安装在所有机器上。不使用第 3 方 DLL。唯一的防火墙是 Windows 防火墙,它对所使用的 TCP 端口有一个例外。所有部署都是从同一个 .msi 完成的,并且文件是相同的。
    • 已修复,这对我来说是一个愚蠢的错误。我尝试更改端口,然后在运行netstat -ano 时注意到端口没有更改。然后我注意到我一直在编辑错误的配置文件。谢谢指点!
    • 嘿大卫,我有同样的问题,我想并尝试了你所说的但没有工作......你能帮我吗?这是相关的问题:Question
    【解决方案2】:

    除了大卫的观点,检查 windows 服务是否正在运行。

    事件日志中有任何错误吗?

    【讨论】:

    • 服务正在运行,除了“服务已启动”之外,事件查看器中没有任何内容。
    猜你喜欢
    • 1970-01-01
    • 2015-11-13
    • 2014-11-04
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2020-03-05
    相关资源
    最近更新 更多