Reputation: 443
How do I find out the endpoint that was called for my WCF service within the authorisation manager?
Current Code:
public class AuthorizationManager : ServiceAuthorizationManager
{
protected override bool CheckAccessCore(OperationContext operationContext)
{
Log(operationContext.EndpointDispatcher.ContractName);
Log(operationContext.EndpointDispatcher.EndpointAddress);
Log(operationContext.EndpointDispatcher.AddressFilter);
//return true if the endpoint = "getDate";
}
}
I want the endpoint that was called, but the results are currently:
MYWCFSERVICE
https://myurl.co.uk/mywcfservice.svc System.ServiceModel.Dispatcher.PrefixEndpointAddressMessageFilter
What I need is the part after the .svc eg/ https://myurl.co.uk/mywcfservice.svc/testConnection?param1=1
In this scenario I want "testConnection" to be returned.
Upvotes: 2
Views: 364
Reputation: 443
Thanks Smoksness! Sent me in the correct direction.
I've made a function that returns the action called:
private String GetEndPointCalled(OperationContext operationContext)
{
string urlCalled = operationContext.RequestContext.RequestMessage.Headers.To.ToString();
int startIndex = urlCalled.IndexOf(".svc/") + 5;
if (urlCalled.IndexOf('?') == -1)
{
return urlCalled.Substring(startIndex);
}
else
{
int endIndex = urlCalled.IndexOf('?');
int length = endIndex - startIndex;
return urlCalled.Substring(startIndex, length);
}
}
Upvotes: 1
Reputation: 10851
Check out this answer.
public class AuthorizationManager : ServiceAuthorizationManager
{
protected override bool CheckAccessCore(OperationContext operationContext)
{
var action = operationContext.IncomingMessageHeaders.Action;
// Fetch the operationName based on action.
var operationName = action.Substring(action.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1);
// Remove everything after ?
int index = operationName.IndexOf("?");
if (index > 0)
operationName = operationName.Substring(0, index);
return operationName.Equals("getDate", StringComparison.InvariantCultureIgnoreCase);
}
}
Upvotes: 1