如何在授权管理器中找到为我的WCF服务调用的端点?
当前代码:
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";
}
}
我想要调用的端点,但目前的结果是:
MYWCFSERVICE
https://myurl.co.uk/mywcfservice.svc System.ServiceModel.Dispatcher.PrefixEndpointAddressMessageFilter
我需要的是.svc之后的部分,例如/ https://myurl.co.uk/mywcfservice.svc/testConnection?param1=1
在这种情况下,我想要" testConnection"被退回。
答案 0 :(得分:1)
查看this回答。
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);
}
}
答案 1 :(得分:1)
谢谢Smoksness!发送给我正确的方向。
我已经创建了一个返回名为
的动作的函数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);
}
}