-
-
Save anand374/8cda138858ced383928984ecb13545e2 to your computer and use it in GitHub Desktop.
Custom Invoker to Invoke the operation only if the Token is valid
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; | |
using System.ServiceModel; | |
using System.ServiceModel.Dispatcher; | |
namespace TokenValidator | |
{ | |
class CustomInvoker : IOperationInvoker | |
{ | |
private readonly IOperationInvoker defaultInvoker; | |
public CustomInvoker(IOperationInvoker defaultInvoker) | |
{ | |
this.defaultInvoker = defaultInvoker; | |
} | |
public bool IsSynchronous | |
{ | |
get { return defaultInvoker.IsSynchronous; } | |
} | |
public object[] AllocateInputs() | |
{ | |
return defaultInvoker.AllocateInputs(); | |
} | |
public object Invoke(object instance, object[] inputs, out object[] outputs) | |
{ | |
// Check the value of the Authorized header added by Message Inspector | |
if (OperationContext.Current.IncomingMessageProperties.ContainsKey("Authorized")) | |
{ | |
bool allow = (bool)OperationContext.Current.IncomingMessageProperties["Authorized"]; | |
if (!allow) | |
{ | |
outputs = null; | |
return null; | |
} | |
} | |
// Otherwise, go ahead and invoke the operation | |
return defaultInvoker.Invoke(instance, inputs, out outputs); | |
} | |
public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state) | |
{ | |
return defaultInvoker.InvokeBegin(instance, inputs, callback, state); | |
} | |
public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result) | |
{ | |
return defaultInvoker.InvokeEnd(instance, out outputs, result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment