私は、クライアントがSilverlightクライアントによって作成された各サービス呼び出しにトークンを追加し、サービスがこのトークンにアクセスしてアプリケーションセキュリティシステムを制御できるカスタムセキュリティ機能を追加しようとしています。 IClientMessageInspectorインターフェイスを実装し、これを生成されたサービスクライアントにリンクすることで、これを実行しようとしています。私はVisual Studioで生成されたプロキシを使用していませんが、ChannelFactoryによって作成された独自のクライントを作成功させましましましました。まずにHthMedのヘックリクリクリクエリクライントを追加するこのヘップロパップロパテクを追加すること
クライアントを生成するコードは次のとおりです。
private ISecurityAdministrationContract CreateChannel()
{
if (factory == null)
{
lock (this)
{
// Create a custom binding that uses HTTP and binary encoding.
var elements = new List<BindingElement>();
elements.Add(new BinaryMessageEncodingBindingElement());
elements.Add(new HttpTransportBindingElement());
var binding = new CustomBinding(elements);
// Create a channel factory for the service endpoint configured with the custom binding.
factory = new ChannelFactory<ISecurityAdministrationContract>(binding, new EndpointAddress(SecurityAdminServiceAddress));
//Add my IClientMessageInspector
factory.Endpoint.Behaviors.Add(new ClientSecurityInterceptor());
}
}
ISecurityAdministrationContract client = factory.CreateChannel();
return client;
}
}
ISecurityAdministrationContract client = factory.CreateChannel();
return client;
}
リクエストにヘッダーを追加するコードは次のとおりです。
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
//Method 1
MessageHeader header = MessageHeader.CreateHeader("MyFirstAuthentication", "ns", "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEEE");
request.Headers.Add(header);
//Method 2
HttpRequestMessageProperty httpRequestMessage;
httpRequestMessage = new HttpRequestMessageProperty();
httpRequestMessage.Headers["MySecondAuthentication"] = "11111111-2222-3333-4444-5555555555555";
request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
return null;
}
上記のコードは両方のテクニックを実装しています。
フィドラーによってトラップされたサービスコールは次のとおりです。(NB httpはht_tpに置き換えられました。
ポストht_tp://127.0.0.1:6785/SecurityAdministrationRelayService.svc/HTTP/1.1 受け入れる:/ 参照元:ht_tp://ipv4.fiddler:6785/ClientBin/Civica.Housing.xap Accept-Language:en-gb Content-Length:400 Content-Type:application/soap + msbin1 MySecondAuthentication:11111111111-222-3333-4444-5555555 Accept-Encoding:gzip、deflate User-Agent:Mozilla/4.0(互換性、MSIE 8.0、Windows NT 5.1; Trident/4.0; GTB5; InfoPath.2; .NET CLR 3.0.04506.648; .NET CLR 3.5.22; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4 ホスト:127.0.0.1:6785 接続:Keep-Alive pragma:no-cache
Vだ S _a_V_D MongFunctionA http://tempuri.org/ISecurityAdministrationContract/CreateAdvocateD mongMobing_mobing9 monGHJ mobing9 mobingD、D * MongFirstAuthentication_ns%AAAAAAA-BBB-CCCDDDEEEEEEEEEEEED [email protected]://ipv4.fiddler:6785/SecurityAdministrationRelayService.svc/ V @_CreateAdvocate_http://tempuri.org/ @ advocateVO mongoWeb{"Id":0、 "UserId":4、 "AdvocateForId":8、 "ValidFrom": "/ Date(1291127869690 + 0000)/"、 "ValidTo":null} __
これには、両方のテクニックのトークン情報が含まれているようです。
この情報を抽出しようとすると、問題がサーバーに表示されます。私はIOperationInvokerを実装し、成功せずにIncomingMessageHeadersのヘッダーを見つけようとしました。私もIncomingMessagePropertiesで検索しましたが、追加されたヘッダーの詳細は表示されません。 これはIOperationInvokerで使用しているコードです:
public object Invoke(object instance, object[] inputs, out object[] outputs)
{
PreInvoke(instance, inputs);
object returnedValue = null;
object[] outputparams = new object[] { };
Exception exception = null;
try
{
returnedValue = originalInvoker.Invoke(instance, inputs, out outputparams);
outputs = outputparams;
return returnedValue;
}
catch (Exception e)
{
exception = e; throw;
}
finally
{
PostInvoke(instance, returnedValue, outputparams, exception);
}
}
protected virtual void PreInvoke(object instance, object[] inputs)
{
//Look for header directly
int index = System.ServiceModel.OperationContext.Current.IncomingMessageHeaders.FindHeader("MyFirstAuthentication", "ns");
//Search via enumerator
foreach (var header in System.ServiceModel.OperationContext.Current.IncomingMessageHeaders)
{
}
}
FindHeaderは-1を返しますが、enumeratorは5つのヘッダーを見つけます。 "Action"、 "MessageID"、 "ReplyTo"、 "VsDebuggerCausalityData"& "To"。
OperationContext.Current.IncomingMessagePropertiesコレクションには、 "Via"、 "Security"、 "Encoder"
実際に、IClientMessageInspectorをClienChannelに追加するクライアントの行をコメントアウトすると、追加された詳細を省略してフィドラーが変更を報告しますが、Incomeingメッセージのヘッダーとプロパティコレクションは変更されません。
どのように私はこの情報にアクセスすることができますか、またはIncomingMessageの一部として提示されていない理由は非常に感謝して受け取ります。