簡體   English   中英

wcf中有多個端點

[英]Multiple endpoints in wcf

我正在嘗試為單個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>

我的第一個端點正在工作,但我的第二個端點不起作用。 這可能有什么不對。 其次,我們為什么不能瀏覽tcp,就像我們可以為HTTP做的那樣。 我知道我們可以使用svcutil測試tcp。 無論如何都要瀏覽TCP。

編輯:

WCF:

http://pastebin.com/gHHRKeYZ

WindowsService:

http://pastebin.com/kjM3iRYj

所有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>

如果您使用的是@Staish配置,則可以嘗試在服務行為中取消注釋此行。

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

然后,您將能夠使用svcutil來創建代理。

如果需要,您可以在發布之前對其進行評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM