访问从客户端消息督察ClientCredential性能 [英] Accessing ClientCredential properties from client message inspector
本文介绍了访问从客户端消息督察ClientCredential性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从客户端消息检查引用代理客户实例?
Can I reference the proxy client instance from a client message inspector?
究其原因,我想访问下列属性的值:
The reason, I'd like to access the values of the following properties:
ClientCredentials.UserName.UserName
ClientCredentials.UserName.Password
感谢
推荐答案
我设法传递引用从我的自定义EndpointBehaviorClientCredentials来从检查中的凭据:
I managed to retrieve the credentials from within the inspector by passing a reference to "ClientCredentials" from my custom EndpointBehavior:
CustomBehaviour:
CustomBehaviour:
public class CustomEndpointBehaviour:IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
ClientCredentials credentials = endpoint.Behaviors.Find<ClientCredentials>();
clientRuntime.MessageInspectors.Add(new CustomMessageInspector(credentials));
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
和检查:
public class CustomMessageInspector : IClientMessageInspector
{
ClientCredentials crendentials = null;
public CustomMessageInspector(ClientCredentials credentials)
{
this.crendentials = credentials;
}
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
string userName = "";
string passWord = "";
if (!(crendentials == null))
{
userName = crendentials.UserName.UserName;
passWord = crendentials.UserName.Password;
}
return null;
}
}
这篇关于访问从客户端消息督察ClientCredential性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文