Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在自定义SecurityTokenAuthenticator实现中访问WCF端点服务类型_C#_Wcf_Web Services_Authentication_Operationcontext - Fatal编程技术网

C# 在自定义SecurityTokenAuthenticator实现中访问WCF端点服务类型

C# 在自定义SecurityTokenAuthenticator实现中访问WCF端点服务类型,c#,wcf,web-services,authentication,operationcontext,C#,Wcf,Web Services,Authentication,Operationcontext,我们需要在WCF服务中使用身份验证/授权服务。我已经实现了自定义客户机/服务凭据,以及相应的令牌和支持类。除了一件事,一切都正常 部分需求是我们可以在服务方法上定义授权角色(通过一个属性),这些角色将与用户信息一起发送给auth服务,auth服务将响应成功/失败消息 我尝试了以下方法: DispatchOperation operation = OperationContext.Current.EndpointDispatcher.DispatchRuntime.Operations.First

我们需要在WCF服务中使用身份验证/授权服务。我已经实现了自定义客户机/服务凭据,以及相应的令牌和支持类。除了一件事,一切都正常

部分需求是我们可以在服务方法上定义授权角色(通过一个属性),这些角色将与用户信息一起发送给auth服务,auth服务将响应成功/失败消息

我尝试了以下方法:

DispatchOperation operation = OperationContext.Current.EndpointDispatcher.DispatchRuntime.Operations.FirstOrDefault(o => o.Action == action);
if (operation != default(DispatchOperation))
{
    Type hostType = OperationContext.Current.Host.Description.ServiceType;
    MethodInfo method = hostType.GetMethod(operation.Name);

    RegistryAuthGroupAttribute authGroupAttribute = (RegistryAuthGroupAttribute)method.GetCustomAttribute(typeof(RegistryAuthGroupAttribute));
    if (authGroupAttribute != null)
    {
        return authGroupAttribute.AuthGroup;
    }
}
这将非常好地。。。如果OperationContext.Current并非始终为null(发现它在身份验证发生后才会填充)


在身份验证阶段期间/之前,我是否有其他选项来获取目标端点的ServiceType?我考虑过使用消息拦截器,但不确定如何获取指定端点的xml并使用它来查找ServiceType。

您从何处调用此代码?这是类似的情况吗:?Th代码肯定是在服务中运行的(而不是像您链接的问题中那样的客户端)。代码需要在令牌身份验证程序中特别运行,这样我就可以获得由属性定义的角色。