C# 使用Active Directory授权WCF服务-拒绝访问错误

C# 使用Active Directory授权WCF服务-拒绝访问错误,c#,asp.net,wcf,wcf-security,C#,Asp.net,Wcf,Wcf Security,我有一个关于WCF通过承载在IIS none生产上的HTTP流量对域帐户进行授权的问题,因此没有ssl证书可在internet上使用 我想知道如何设置从客户端到web服务的windows身份验证。目前我正在同一个局域网上进行测试,所以代理不是问题 我在这篇文章的末尾列出了一系列尝试过的步骤 编辑:正在发生的错误只是访问被拒绝,而不是来自 尝试,在客户端应用程序中捕获。如果有办法获得更详细的信息,请让我知道,我会将结果添加到帖子中 WCF服务代码: [AspNetCompatibilityRequ

我有一个关于WCF通过承载在IIS none生产上的HTTP流量对域帐户进行授权的问题,因此没有ssl证书可在internet上使用

我想知道如何设置从客户端到web服务的windows身份验证。目前我正在同一个局域网上进行测试,所以代理不是问题

我在这篇文章的末尾列出了一系列尝试过的步骤

编辑:正在发生的错误只是访问被拒绝,而不是来自 尝试,在客户端应用程序中捕获。如果有办法获得更详细的信息,请让我知道,我会将结果添加到帖子中

WCF服务代码:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]  

ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]    

public class Data : IData
    {
        [PrincipalPermission(SecurityAction.Demand, Role=@"Administrators")]

        public List<Incident> GetCases()
        {            

            Queries query = new Queries();

            List<Incident> iList = query.CallCases();

            return iList;

         }
   }
WCF Web配置绑定:

<wsHttpBinding>
    <binding name="TransportSecurity">
        <security mode="None">
            <message clientCredentialType="Windows" algorithmSuite="Default"/>
        </security>
    </binding>
</wsHttpBinding>
WCF Web配置行为:

<behavior name="Behaviour1">
    <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
    <serviceDebug includeExceptionDetailInFaults="true" />
    <useRequestHeadersForMetadataAddress>
        <defaultPorts>
            <add scheme="http" port="9577" /> ///This port is correct
        </defaultPorts>
    </useRequestHeadersForMetadataAddress>
</behavior>
WCF Web配置服务:

<service behaviorConfiguration="Behaviour1" name="WebService1.Data">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="WebService1.IData">
         <identity>
              <dns value="demo.DomainName.co.uk" />
         </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
客户端应用程序已添加服务引用

            DataClient client = new DataClient();

        AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        PrincipalPermission principalPerm = new PrincipalPermission(null, "Administrators");
        principalPerm.Demand();
        Console.WriteLine("Demand succeeded.");

        client.ClientCredentials.Windows.ClientCredential.Domain = "Domain Name";
        client.ClientCredentials.Windows.ClientCredential.UserName = "User Account";
        client.ClientCredentials.Windows.ClientCredential.Password = "Password";

        //client.ClientCredentials.UserName.UserName = @"UserAccount@domain.com";
        //client.ClientCredentials.UserName.Password = "Password";
        //client.ClientCredentials.UseIdentityConfiguration = true;

        try
        {
            List<Incident> cases = client.GetCases().ToList();

            foreach (Incident Inc in cases)
            {
                Console.WriteLine(Inc.CaseID);
            }

        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
试图解决的问题:

使用域和本地用户 将客户端凭据类型修改为basic、NTLM和Windows 使用设置IIS以使用 IIS已启用基本身份验证和Windows身份验证 如果您需要更多信息,请随时询问


感谢您提供的任何帮助

@Tim为我指明了正确的方向,这就是解决方案:

<wsHttpBinding>
<binding name="TransportSecurity">
    <security mode="Message">
        <message clientCredentialType="Windows" algorithmSuite="Default"/>
    </security>
</binding>
</wsHttpBinding>
因为我没有SSL证书,所以我需要将安全模式设置为Message,当大多数人使用SSL进行测试时,我感到困惑,因为SSL同样需要传输安全性,我已经将其设置为None进行测试


谢谢你的帮助,Tim

欢迎来到SO。你第一次在海报上写了一个很好的问题,但我认为有一个小而重要的信息缺失了——即,你看到的行为或错误是什么?另外,我认为将securityMode设置为None可能会影响您的尝试-子安全设置可能会被忽略,这只是我的猜测。谢谢Tim,完全忘了添加它,我现在已经添加了它。谢谢你的热情欢迎