C# WCF - 查找被调用的端点的名称

标签 c# wcf authorization

如何找到授权管理器中为我的 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/

相关文章:

c# - 使用ajax在iframe中加载内容

c# - 使用 win 表单组合框 Items.AddRange 方法

c# - 启用 HTTPS、IIS 托管的 WCF 服务,如何保护它?

mongodb - 无法授权新创建的 MongoLabs 数据库

azure - 对在 Web api 中登录外部应用程序的用户进行身份验证

c# - 引用所需的重载泛型方法

c# - 绘制不模糊的路径

c# - C# 中内存占用最少的最快的序列化器和反序列化器?

javascript - 404 未找到加密值

asp.net-core - 如何使用 Microsoft Graph API 获取 .net 核心应用程序中的所有授权组?