C# wcf webhttpbindig中的自定义授权和身份验证

C# wcf webhttpbindig中的自定义授权和身份验证,c#,wcf,authentication,authorization,webhttpbinding,C#,Wcf,Authentication,Authorization,Webhttpbinding,我使用webhttpbinding创建了一个简单的wcf服务,如您所见: [OperationContract] [WebInvoke(Method = "GET", UriTemplate = "/Data/{data}")] string GetData(string data); 以及实施: public string GetData(string value) { return string.Format(

我使用webhttpbinding创建了一个简单的wcf服务,如您所见:

    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "/Data/{data}")]
    string GetData(string data);
以及实施:

   public string GetData(string value)
        {

                return string.Format("You entered: {0}", value);

        }
我想在大约两周内创建一个自定义授权和身份验证,但我不能。我搜索了很多,但我可以找到wshttpbinding的身份验证,而不是webhttpbinding

我最近提出的问题描述了主要问题:

您可以通过webhttpbinding实现为WCF服务提供授权

您的代码可能与此类似:

public class CustomAuthorizationManager : ServiceAuthorizationManager
{
    protected override bool CheckAccessCore(OperationContext operationContext)
    {
        try
        {
            ServiceSecurityContext securityContext = operationContext.ServiceSecurityContext;
            WindowsIdentity callingIdentity = securityContext.WindowsIdentity;

            WindowsPrincipal principal = new WindowsPrincipal(callingIdentity);
            return principal.IsInRole("Administrators");
        }
        catch (Exception)
        {
            return false;
        }
    }
}
然后在web.config文件中注册自定义ServiceAuthorizationManager:

<serviceBehaviors>
  <behavior name="ServiceBehaviour">
    <serviceMetadata httpsGetEnabled="true"/>
    <serviceAuthorization serviceAuthorizationManagerType="YourNamespace.CustomAuthorizationManager, YourAssemblyName"/>
  </behavior>
</serviceBehaviors>


谢谢,但是如何检查角色。我的意思是如何检查用户角色是否正确执行操作?
principal.IsInRole(“管理员”)当我调用服务IsInRole返回FALSE时,我想用我的数据库角色检查操作角色,