1

我正在尝试为单个 WCF 服务执行多个端点,以便每个端点都有其单独的接口/方法。我正在使用 TCP

app.config

<configuration>
  ....
  <system.serviceModel>
    <services>
      <service name="WCFLibrary.CalculatorService">
          <host>
            <baseAddresses>
              <!--<add baseAddress="http://localhost:8788/CalculatorService/" />-->
              <add baseAddress="net.tcp://localhost:8523/CalculatorService" />
            </baseAddresses>
          </host>
          <endpoint name="ServiceTCPEndPoint" 
              address="" 
              binding="netTcpBinding" 
              contract="WCFLibrary.ICalculator">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
          <endpoint name="ServiceMexEndPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      </service>
      <service name ="WCFLibrary.MyWorldService">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8524/MyWorldService"/>
          </baseAddresses>
        </host>
        <endpoint name="HelloWorldTCPEndpoint" 
            address="" 
            binding="netTcpBinding" 
            contract="WCFLibrary.MyWorld">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint name="HelloWorldMexEndPoint" 
            address="mex" 
            binding="mexTcpBinding" 
            contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我的第一个端点正在工作,但我的第二个端点不起作用。这里可能有什么问题。其次,为什么我们不能像浏览 HTTP 一样浏览 tcp。我知道我们可以使用 svcutil 测试 tcp。反正有没有浏览TCP。

编辑:

周转基金:

http://pastebin.com/gHHRKeYZ

Windows服务:

http://pastebin.com/kjM3iRYj

4

2 回答 2

2

所有 net.tcp 端点都应该使用相同的端口,使用端口共享

MSDN 中有几篇文章/教程,以及如何实现这一点的其他地方。这是一个

试试这个配置设置

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="tcpDefault" portSharingEnabled="true" />

  </netTcpBinding>
</bindings>
<services>
  <service name="WCFLibrary.CalculatorService">

      <host>
        <baseAddresses>
          <!--<add baseAddress="http://localhost:8788/CalculatorService/" />-->
          <add baseAddress="net.tcp://localhost:8523/CalculatorService" />
        </baseAddresses>
      </host>
      <!-- Service Endpoints -->
      <!-- Unless fully qualified, aBddress is relative to base address supplied above -->
      <endpoint name="ServiceTCPEndPoint" address="" binding="netTcpBinding" bindingConfiguration="tcpDefault" contract="WCFLibrary.ICalculator">
        <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <!-- Metadata Endpoints -->
      <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
      <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
      <endpoint name="ServiceMexEndPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    </service>
  <service name ="WCFLibrary.MyWorldService">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8523/MyWorldService"/>
      </baseAddresses>
    </host>
    <endpoint name="HelloWorldTCPEndpoint" address="" binding="netTcpBinding"  bindingConfiguration="tcpDefault" contract="WCFLibrary.MyWorld">
      <identity>
        <dns value="localhost" />
      </identity>

    </endpoint>
    <endpoint name="HelloWorldMexEndPoint" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, 
      set the values below to false before deployment -->
      <!--<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False" />-->
      <serviceMetadata/>
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true.  Set to false before deployment 
      to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>

于 2014-07-31T15:43:19.477 回答
1

If you are using @Staish configuration, you can try to uncomment this line in the service behaviour.

 <!--<serviceMetadata httpGetEnabled="**True**" httpsGetEnabled="False" />-->

Then you'll be able to use the svcutil to create the proxy.

You can comment it back before publishing if you want.

于 2014-08-07T14:28:56.500 回答