12

いくつかのWCFサービスを含むアセンブリがあり、それぞれに独自の契約があります。それはすべてうまく機能します。サービスのapp.configのサービス構成は次のようになります。

<services>
  <service behaviorConfiguration="WcfService.AlyzaServiceBehavior"
    name="Sam.Alyza.WcfService.ServiceWebsites">
    <endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceWebsites">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/Websites/" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="Sam.Alyza.WcfService.LogReaderServiceBehavior"
    name="Sam.Alyza.WcfService.ServiceLogReader">
    <endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceLogReader">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/LogReader/" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="Sam.Alyza.WcfService.ServiceSystemverwaltungBehavior"
    name="Sam.Alyza.WcfService.ServiceSystemverwaltung">
    <endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceSystemverwaltung">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/Systemverwaltung/" />
      </baseAddresses>
    </host>
  </service>
  [...]
</services>

より大きなプロジェクトを念頭に置いており、より多くの契約があるので、異なるサービス契約間でBaseAddressを共有する方法が必要です。
これが異なるコントラクトとエンドポイントを持つ1つのサービスである場合、オモンのベースアドレスを設定できますが、複数のサービスに共通のベースアドレスを設定するにはどうすればよいですか?

もちろん、私はクライアントのために似たようなものが必要です。

4

3 に答える 3

10

すべてのコントラクトを1つのクラスに組み合わせることができるため、コントラクトごとにベースアドレスと1つ(または複数)のエンドポイントを持つ1つのサービスがあります。

大きなクラスファイルが1つになるのを避けるために、部分キーワード(c#を使用すると仮定)を使用して、クラスを複数のファイルに分割できます。各ファイルは1つのコントラクトを実装できるため、個々のインターフェイスの保守がはるかに簡単になります。

C ++では、#includesまたは多重継承を使用できますが、それは大量の規律を意味します...

構成は次のようになります。

<services>
  <service behaviorConfiguration="WcfService.AlyzaServiceBehavior"
    name="Sam.Alyza.WcfService.ServiceAll">
    <endpoint address="Websites/" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceWebsites">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="LogReader/" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceLogReader">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="Systemverwaltung/" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceSystemverwaltung">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/" />
      </baseAddresses>
    </host>
  </service>
</services>
于 2009-01-13T09:15:55.580 に答える
2

サービスはBaseAddress値を共有できます(Net.Tcpポート共有サービスが実行されている場合はポート番号を含む)。一意である必要があるのはエンドポイントアドレスです。構成ファイルで、各ServiceHostのMEXエンドポイントのアドレスが「mex」であることに注意してください。他のエンドポイントのアドレスは空の文字列です。エンドポイントの相対アドレスを(少なくとも構成ファイルで)WCFに指定すると、ベースアドレスがその前に付加されます。したがって、LogReaderサービスのMEXエンドポイントアドレスは「net.tcp:// localhost:8731 / Design_Time_Addresses / SamAlyza / LogReader/mex」です。

メインサービスエンドポイントに相対アドレスが設定されていないため、ServiceHostのベースアドレスがメインサービスエンドポイントの実際のアドレスとして使用されます。2つのエンドポイントが重複するUri.AbsolutePath値を持つことはできないため、この例では、ベースアドレス値を共有できないと思われます。WCFサービスをホストするServiceHostクラスには組み込みのエンドポイントがありませんが、ServiceEndpointクラスには、指定した設定に基づいて入力されるListenUriプロパティがあります。

例のbaseAddress値をすべて一致するように変更した場合、Endpoint要素に一意の相対アドレス値を設定している限り、すべてが機能するはずです。ただし、現在、すべてのエンドポイントのアドレスが「mex」であるため、MEXエンドポイントでいくつかの問題が発生する可能性があるようです。それらをユニークにして、あなたは元気になるはずです。

さて、私は尋ねなければなりません、あなたはこれらのサービスがベースアドレスではなく名前空間を共有することを単に望んでいないのですか?

于 2009-01-12T19:07:45.043 に答える