无法让WCF使用netTcpBinding

时间:2009-08-28 03:25:32

标签: .net wcf nettcpbinding

以下是我的app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Indexer">
        <endpoint address="net.tcp://localhost:8000/Indexer/" binding="netTcpBinding"
          bindingConfiguration="TransactionalTCP" contract="Me.IIndexer" />
      </service>
      <service name = "Indexer" behaviorConfiguration = "MEXGET">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8000/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name = "MEXGET">
          <serviceMetadata httpGetEnabled = "true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="TransactionalTCP"
           transactionFlow="true"
         />
      </netTcpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

出于某种原因,我无法在运行此操作的计算机上访问WCF服务。 任何人都可以发现错误吗?我启动并运行了netTcpBinding服务。

当我在HTTP中运行相同时,它可以正常使用以下.config文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="IndexerServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8080/Indexer/"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Indexer" behaviorConfiguration="IndexerServiceBehavior">
        <endpoint address="http://localhost:8080/Indexer/" binding="basicHttpBinding"
            bindingConfiguration="" name="HTTP" contract="IIndexer" />
        <endpoint address="http://localhost:8080/Indexer/MEX/" binding="mexHttpBinding"
            bindingConfiguration="" name="MEX" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

我无法弄清楚我做错了什么..

3 个答案:

答案 0 :(得分:3)

当然,你打开防火墙让它听?

如果它有用,这是我很久以前成功使用的绑定:

<services>

  <service name="MyService.MySearch" behaviorConfiguration="ServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://mypc:8003/MyService"/>
      </baseAddresses>
    </host>
    <endpoint bindingConfiguration="Binding1"
              binding="netTcpBinding"
              contract="MyService.IMySearch"
              address="net.tcp://mypc:8004/MyService"  />
  </service>
</services>
<bindings>
  <netTcpBinding>
    <binding name="Binding1"
             hostNameComparisonMode="StrongWildcard"
             sendTimeout="00:10:00"
             maxReceivedMessageSize="65536"
             transferMode="Buffered"
             portSharingEnabled="false">
      <security mode="None">
        <transport clientCredentialType="None" />
        <message clientCredentialType="None" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
    </behavior>
  </serviceBehaviors>
</behaviors>

这种绑定没有安全保障。

答案 1 :(得分:1)

您可能需要Enable the Net.TCP Port Sharing Service。从MSDN引用:

  

Windows Communication Foundation(WCF)   使用名为的Windows服务   Net.TCP端口共享服务   促进TCP端口的共享   跨多个流程。这个   服务是作为WCF的一部分安装的,   但该服务未启用   默认为安全预防措施   所以必须在之前手动启用   第一次使用。本主题介绍如何操作   配置Net TCP端口共享   使用Microsoft管理服务   控制台(MMC)管理单元。

祝你好运!

答案 2 :(得分:0)

尝试使用不同的端口号进行http和net.tcp绑定。端口共享具有不同的目的,在多个进程之间共享相同的net.tcp端口。