0
我可以從客戶端消息檢查器引用代理客戶端實例嗎?從客戶端消息檢查器訪問ClientCredential屬性
究其原因,我想訪問下列屬性的值:
ClientCredentials.UserName.UserName
ClientCredentials.UserName.Password
感謝
我可以從客戶端消息檢查器引用代理客戶端實例嗎?從客戶端消息檢查器訪問ClientCredential屬性
究其原因,我想訪問下列屬性的值:
ClientCredentials.UserName.UserName
ClientCredentials.UserName.Password
感謝
我設法通過傳遞引用「ClientCredentials」來檢索檢查中的憑據從我的自定義EndpointBehavior:
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;
}
}