私はここで問題に直面しています。私はデータを取得するために呼び出す WCF Web サービスであるクライアント/サーバー プロジェクトを行っています。転送の膨大なデータのため、バインディングをカスタム バインディングにプログラムで (構成ファイルではなく) 変更する必要がありました。
カスタムバインディングとも呼ばれる新しいユーザー定義バインディングを作成しています。クラスの例は次のとおりです。
public class MyCustomBinding : CustomBinding
関数 BindingElementCollection をオーバーライドします。
public override BindingElementCollection CreateBindingElements()
{
WSHttpBinding wSHttpBinding = new WSHttpBinding("RMSKeberosBinding"); //this is to load the configuration from app.config. because i want to copy the setting of wsHttpConfig to my custom binding.
BindingElementCollection wSHttpBindingElementCollection = wSHttpBinding.CreateBindingElements();
TransactionFlowBindingElement transactionFlowBindingElement = wSHttpBindingElementCollection.Remove<TransactionFlowBindingElement>();
SymmetricSecurityBindingElement securityElement = wSHttpBindingElementCollection.Remove<SymmetricSecurityBindingElement>();
MessageEncodingBindingElement textElement = wSHttpBindingElementCollection.Remove<MessageEncodingBindingElement>();
HttpTransportBindingElement transportElement = wSHttpBindingElementCollection.Remove<HttpTransportBindingElement>();
GZipMessageEncodingBindingElement gzipElement = new GZipMessageEncodingBindingElement(); // this is from microsoft sample. i want to add gzip as a compress to my message.
BindingElementCollection newCol = new BindingElementCollection();
newCol.Add(transactionFlowBindingElement);
newCol.Add(securityElement);
newCol.Add(gzipElement);
newCo .Add(transElement);
return newCol;
}
私がやろうとしているのは、wshttpbinding からすべての設定をコピーし、メッセージ エンコーダーとして gzip を追加することです。 暗号化されたデータを圧縮すると、元のデータ サイズよりも大きなサイズになります。 これは、WSHttpBinding の SymmetricSecurityBindingElement が暗号化を行ったためです。これを正しい方法で行うには?wshttpbinding からのセキュリティ設定と、gzip が機能するようにします。