-
-
Save anand374/76c001117e32595e7dc7b79c86c39575 to your computer and use it in GitHub Desktop.
Endpoint Behavior to inject the Message Inspector and Custom Invoker to WCF Pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ServiceModel.Channels; | |
using System.ServiceModel.Description; | |
using System.ServiceModel.Dispatcher; | |
namespace TokenValidator | |
{ | |
public class BearerTokenEndpointBehavior : IEndpointBehavior | |
{ | |
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) | |
{ | |
} | |
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) | |
{ | |
} | |
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) | |
{ | |
ChannelDispatcher channelDispatcher = endpointDispatcher.ChannelDispatcher; | |
if (channelDispatcher != null) | |
{ | |
foreach (EndpointDispatcher ed in channelDispatcher.Endpoints) | |
{ | |
ed.DispatchRuntime.MessageInspectors.Add(new BearerTokenMessageInspector()); | |
} | |
} | |
foreach (var operation in endpoint.Contract.Operations) | |
{ | |
if (operation.Behaviors.Contains(typeof(MyOperationBehavior))) | |
continue; | |
operation.Behaviors.Add(new MyOperationBehavior()); | |
} | |
} | |
public void Validate(ServiceEndpoint endpoint) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment