无法点击ApplyClientBehavior方法
使用 System.ServiceModel.Description;
namespace Utils.CMSAuth
{
public class AuthorizationHeaderEndpointBehavior : IEndpointBehavior
{
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
clientRuntime.ClientMessageInspectors.Add(new AuthorizationHeaderMessageInspector(TokenGenerator.GetToken()));
}
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
}
未点击ApplyClientBehavior方法。
在 web.config 端添加了行为。
<extensions>
<behaviorExtensions>
<add name="AuthorizationHeaderMessageInspector" type="Utils.CMSAuth.CustomBehaviorExtensionElement, Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
您可以通过如下代码向客户端添加行为:
client.Endpoint.Behaviors.Add(new AuthorizationHeaderEndpointBehavior(null, true, true));
您还可以尝试修改客户端的 app.config 配置文件。这篇文章解释得更好: