http://megakemp.com/2009/02/06/managing-shared-cookies-in-にあるヘッダー「集中型Cookie管理」で概説されているこの方法でWCFサービス呼び出しを行うときに、共有認証Cookieを管理しています。 wcf /
IClientMessageInspector
カスタム、、、作品IEndpointBehavior
を設定しましたBehaviorExtensionElement
。私のエンドポイントの動作は、次のようにメッセージインスペクターを追加します。
public class MyEndpointBehavior : IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
// yuck.. Wish I had an instance of MyClientMessageInspector
// (which has the auth cookie already) so I could just inject that
// instance here instead of creating a new instance
clientRuntime.MessageInspectors.Add(new MyClientMessageInspector());
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
すべて問題なく動作しますが、複数のクライアント間でCookieを共有する場合、このソリューションは機能しなくなります。このApplyDispatchBehavior()
メソッドは新しいインスタンスを作成するため、他のクライアントはそのメッセージインスペクターインスタンス、つまり認証チケットを取得しません。
そこで、次のようにインスタンスを挿入できるカスタムコンストラクターを作成しようと考えました。
MyEndpointBehavior(MyClientMessageInspector msgInspector) { ... }
ただし、WCFにはパラメーターのないコンストラクターが必要です。インターネットを介して除草するWCFには、依存性注入、作成などを可能にするフックがIInstanceProvider
ありIServiceBehavior
ます。しかし、それが私がここで探しているものではないと思います。
誰かが私を正しい方向に導くのを手伝ってもらえますか?