1

私はsvcファイルが作成されるwcfサービスアプリケーションで作業しています。今、私は、人々が http url と tcp url によって私のサービスに接続できるように私のサービスを設計したいと考えています。

そのため、wshttp 用に 1 つ、wsDualhttp 用に 1 つ、tcp 用に 1 つ、構成に 3 つのエンドポイントを追加したいと思います。wshttp、wsDualhttp、および tcp の 3 つのエンドポイントを含む構成エントリのサンプルを誰かに提供してください。

この場合、wshttp、wsDualhttp、および tcp 用に 3 つの異なる mex エンドポイントが必要ですか。

また、クライアント側でプロキシ クラスを作成できる URL を 3 つ教えてください。ありがとう

4

1 に答える 1

1

次のようなものを持つことができます(セルフホスティングを仮定すると、完全なサービスアドレスを自分で実際に決定できるためです-IISでホスティングすると、サービスアドレスは.svcファイルが存在する場所によって最も決定されます):

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="YourNamespace.YourService" behaviorConfiguration="Default">
        <endpoint name="Default" 
            address="http://YourServer/Services/MyService" 
            binding="basicHttpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="TCP" 
            address="net.tcp://YourServer/ServicesTCP/MyService" 
            binding="netTcpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="mex" 
            address="http://YourServer/Services/MyService/mex" 
            binding="mexHttpBinding" 
            contract="IMetadataExchange"/>
        <endpoint name="Dual" 
            address="http://YourServer/Services/MyService/Dual" 
            binding="wsDualHttpBinding" 
            clientBaseAddress="http://localhost:8001/client/"
            contract="YourNamespace.IYourDualService"/>
      </service>
    </services>
  </system.serviceModel>

これにより、次の 3 つのエンドポイントが定義されます。

  • http://YourServer/Services/MyServiceサービスの HTTP エンドポイント
  • http://YourServer/Services/MyService/mexメタデータ交換用のHTTP MEX エンドポイント(サービスの検出可能性)
  • net.tcp://YourServer/ServicesTCP/MyServiceサービスの Net.TCP エンドポイント

もちろん、設定を簡単にするために2 つのベース アドレスを使用することもできます。

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="YourNamespace.YourService" behaviorConfiguration="Default">
        <host>
          <baseAddresses>
            <add baseAddress="http://YourServer/Services"/>
            <add baseAddress="net.tcp://YourServer/ServicesTCP"/>
          </baseAddresses>
        </host>
        <endpoint name="Default" 
            address="MyService" 
            binding="basicHttpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="TCP" 
            address="MyService" 
            binding="netTcpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="mex" 
            address="MyService/mex" 
            binding="mexHttpBinding" 
            contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>

これにより、同等のサービス エンドポイントが構成されます。

は、コールバック メカニズムwsDualHttpBindingに少なくとも が必要であるという点で異なりclientBaseAddressます (WCF サービスはクライアントにコールバックして、ステータス メッセージなどを送り返します)。wsHttpBinding- 別途行う必要があります。しかし、基本的には- それはまだほとんどすべて同じことです....

更新:トピックを読んだ後(私があまり頻繁に使用するものではありません)、二重通信は を使用しても実際に可能であるように見えnetTcpBindingますが、サービスを自己ホストしている場合にのみ - IIS は二重通信をサポートしていませんnetTcpBinding.

二重サービスを作成するには、追加の手順と追加のコードが必要です。そのため、非二重basicHttpBindingまたは二重のサービスをwsHttpBinding同時に使用することはできません。したがって、この例で を使用して別のエンドポイントを持つことは、実際には意味がありません。wsDualHttpBindingなぜなら、そのサービスは実際には二重である必要があるためです (その後、wsDualHttpBindingandを使用できますnetTcpBinding) - または二重ではない - その後basicHttpBinding、 、wsHttpBindingnetTcpBindingおよびさらにいくつかを使用できます。"エキゾチックなバインディング (MSMQ、名前付きパイプなど)

于 2013-01-04T16:17:09.980 に答える