如何找到授权管理器中为我的 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";
}
}
我想要调用的端点,但当前结果是:
MYWCF服务
https://myurl.co.uk/mywcfservice.svc System.ServiceModel.Dispatcher.PrefixEndpointAddressMessageFilter
我需要的是.svc之后的部分,例如/ https://myurl.co.uk/mywcfservice.svc/testConnection?param1=1
在这种情况下,我希望返回“testConnection”。
最佳答案
查看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);
}
}
关于C# WCF - 查找被调用的端点的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38636972/