【发布时间】:2015-04-01 16:38:27
【问题描述】:
我有一个关于通过 IIS 上托管的 HTTP 流量对域帐户进行 WCF 授权的问题(没有生产,因此没有 ssl 证书可通过 Internet 使用)
我想知道如何设置从客户端到我的 Web 服务的 Windows 身份验证。目前我正在同一个 LAN 上进行测试,所以代理不是问题
我在这篇文章的末尾包含了一个尝试过的步骤列表
编辑:发生的错误只是访问被拒绝,没有别的,从 尝试,在客户端应用程序中捕获。如果有办法获得更详细的信息,请告诉我并将结果添加到帖子中。
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);
}
尝试的解决方案:
- 使用域和本地用户
- 将客户端凭据类型修改为基本、NTLM 和 Windows
- 使用设置IIS来使用
- IIS 已启用基本和 Windows 身份验证
如果您需要更多信息,请随时询问。
感谢您提供的任何帮助
【问题讨论】:
-
欢迎来到 SO。你为第一次发帖写了一个很好的问题,但我认为缺少一个小而重要的信息——即你看到的行为或错误是什么?另外,我认为将
securityMode设置为“无”可能会影响您尝试执行的操作 - 可能会忽略子安全设置(这只是我的猜测)。 -
谢谢蒂姆,完全忘记添加了,我现在已经添加了。感谢您的热烈欢迎
标签: c# asp.net wcf wcf-security