我能否在托管在IIS之外的WCF服务中使用netTcpBinding?

3

我的WCF服务作为Windows托管服务运行,因此我不确定是否仍然可以使用netTcpBinding。我尝试遵循MSDN上的一些指南,但是每当我从basicHttpBinding切换时,我的服务总是无法启动。也许在IIS之外的服务需要进行额外的步骤?


你应该完全能够做到这一点。你可以分享相关的配置位吗? - Tad Donaghe
netTcpBinding可用于Windows服务托管的端点。您能否给我们提供更多上下文信息(错误消息,服务定义信息等)? - dlev
@Terry @dlev:我正在使用installutil.exe启动服务,该服务在VS2010之外运行,因此我不确定如何获取异常消息。这是我的app.config:http://pastebin.com/s3ibabxw - rafale
你的配置文件中存在一些错误,例如baseAddress是http协议,而你启用了httpGetEnabled来获取元数据,但是你的终端却是HTTP协议。请参考我的答案进行修改。 - Alex Aza
2个回答

4

是的,您可以在Windows服务或甚至控制台应用程序中使用netTcpBinding托管WCF服务。

以下是配置文件示例:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <serviceMetadata />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="ServiceBehavior"
             name="XX.XX.Service">
      <endpoint address=""
                binding="netTcpBinding"
                bindingConfiguration="BindingConfiguration"
                contract="XX.XX..IService" />
      <endpoint address="mex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8731/XXService" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <bindings>
    <netTcpBinding>
      <binding
        name="BindingConfiguration">
        <security mode="None" />
      </binding>
    </netTcpBinding>
  </bindings>
</system.serviceModel>

[编辑]

您的配置文件存在以下问题:

  • 基础地址应为net.tcp而非http
  • 元数据终结点应为metTcpBinding而非mexHttpBinding
  • 安全性 - 默认情况下将使用Windows授权,如果在两个框之间测试通信,则可能会出现权限问题。建议在一切正常时从安全模式None开始,然后再调整安全性。
  • 无需为服务行为指定httpGetEnabled
  • 如果要使用的端口已被占用,您将无法启动服务

2
你绝对可以这样做,我甚至认为你应该这样做。
以下是你面临的问题:
<services>
   <service name="Server.FileService" ...
      <host>
         <baseAddresses>
            <add baseAddress="http://localhost:8000/Test/file"/>
         </baseAddresses>
      </host>
      <endpoint address="" binding="netTcpBinding" contract="Server.IFile" />
      <endpoint address="mex" binding="mexHttpBinding" ...

net.tcp地址必须以net.tcp://前缀而不是http://前缀开头。

我通常不使用baseAddress,所以无法提供建议。我会移除baseAddress并改用:

      <endpoint address="net.tcp://localhost:8001/Test/file" ..

(请注意,我也会选择另一个端口而不是8000)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接