16

下位互換性をサポートする必要があるクライアント サーバー アプリケーション (.NET 4 WPF、WCF) に取り組んでいます。言い換えれば、操作契約とデータ契約に関しては、古いクライアントは新しいサーバーと互換性がある必要があります (逆も同様です)。

私たちの WCF サービスは IIS でホストされており、 basicHttpBinding を使用するよう設定されています。

<basicHttpBinding>
   <binding name="basicHttpBinding_Configuration" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
         maxArrayLength="2147483647" />
      <security mode="None" />
   </binding>
</basicHttpBinding>

...

<service behaviorConfiguration="SampleGateway.Data.DataAccessBehavior"
   name="SampleGateway.Data.DataAccess">
   <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_Configuration"
      contract="Sample.Data.IDataAccess" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <host>
      <baseAddresses>
         <add baseAddress="http://localhost:8731/Design_Time_Addresses/SampleGateway/SampleGateway.Data.DataAccess.svc" />
      </baseAddresses>
   </host>
</service>

...

<behavior name="SampleGateway.Data.DataAccessBehavior">
   <serviceMetadata httpGetEnabled="true" />
   <serviceDebug includeExceptionDetailInFaults="false" />
   <dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>

コントラクトは非常に基本的なもので、次のようになっているとします。

[ServiceContract]
public interface IDataAccess
{
   [OperationContract]
   List<Data> GetData(List<int> ids, DateTime startDateTime, DateTime endDateTime);
}

最近、エンコーディングを からXMLに変更できることを発見しましたbinary。IIS 圧縮と組み合わせることで、上記の GetData などの WCF メソッドのパフォーマンスが大幅に向上しました。

このエンコーディングの変更には、クライアントとサーバーの WCF バインディングの変更も必要で、 から に切り替えbasicHttpBindingましたcustomBinding

<customBinding >
   <binding name="binaryHttpBinding_Configuration">
      <binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647">
         <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647"/>
      </binaryMessageEncoding>
      <httpTransport transferMode="Streamed" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" useDefaultWebProxy="true"/>
   </binding>
</customBinding>

...

<service behaviorConfiguration="SampleGateway.Data.DataAccessBehavior"
   name="SampleGateway.Data.DataAccess">
   <endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding_Configuration"
      contract="CEMLink.Data.IDataAccess" />
   <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   <host>
      <baseAddresses>
         <add baseAddress="http://localhost:8731/Design_Time_Addresses/SampleGateway/SampleGateway.Data.DataAccess.svc" />
      </baseAddresses>
   </host>
</service>

...

これが問題です。私たちのソフトウェアはクライアント/サーバーの下位互換性をサポートする必要があるため、古いクライアントが古いbasicHttpBindingを使用してサーバーにヒットしようとするとcustomBinding、呼び出しは不一致で失敗します。"Content Type text/xml; charset=utf-8 was not supported by this service.... The client and service bindings may be mismatched"

同じサービス コントラクトに 2 つのバインド構成 (1 つは基本、もう 1 つはカスタム) を設定し、両方が同じインターフェイスを指すことはできますか? どうすればこれを回避できますか?

4

2 に答える 2

0

同じサービス コントラクトに対して 2 つの異なるバインディングを使用できますが、構成で個別のサービス ノードを作成する必要があり、個別のエンドポイントも定義する必要があります。そのため、バイナリ形式のサービス用に新しいエンドポイントを作成し、新しいバージョンのクライアントがそれを参照するようにします。

于 2013-06-19T21:33:46.727 に答える