通过WebHttpBinding在Kerberos模式下连接自托管WCF服务失败

时间:2014-08-15 06:12:46

标签: c# wcf kerberos webhttpbinding

我有一个可以使用WebHttpBinding访问的自托管WCF服务。此服务应从客户端上的Internet Explorer获取kerberos令牌,然后他应使用此令牌模拟通过其他服务器上的网络共享访问文件服务器。

喜欢这个链:

IE (Client) -> WCF-Service (BI-Server) -> impersonate -> access network share on file server

但是,如果我更改ClientCredentialType或使用Kerberos设置添加ServiceAuthenticationBehavior(401 Unauthorized),IE会显示登录对话框。

使用NTLM,我可以访问WCF服务并模拟,但访问文件服务器会导致UnauthorizedAccessException

同一台服务器还有一个带有Kerberos的NetTcpBinding,可以正常工作。

我做错了什么?

在BI服务器上激活Kerberos(所有服务)的委派。

  • ADS-Functional Level是2012
  • 文件服务器是Windows Server 2003
  • WCF / IIS-Host是Windows Server 2012 R2
  • 客户端是Windows 8,IE 10

现在是频道的代码:

var listenUrl =  "http://0.0.0.0:8735";

var bind = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly)
{
         Security = {Transport = {ClientCredentialType = HttpClientCredentialType.InheritedFromHost}},
         TransferMode = TransferMode.StreamedResponse
};

var host = new WebServiceHost(typeof(C_SIS), new Uri(listenUrl));
host.AddServiceEndpoint(typeof(IW_SIS), bind, "").Behaviors.Add(new WebHttpBehavior());

ServiceAuthenticationBehavior sab = null;
sab = host.Description.Behaviors.Find<ServiceAuthenticationBehavior>();
if (sab == null)
{
         sab = new ServiceAuthenticationBehavior();
         sab.AuthenticationSchemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.Ntlm;
         host.Description.Behaviors.Add(sab);
}
else
{
         sab.AuthenticationSchemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.Ntlm;
}

host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(UnbekannterRecv);
host.Open();

1 个答案:

答案 0 :(得分:0)

首先,检查您的服务是否使用域用户运行。 然后,您必须为此用户设置SPN(服务主体名称)。

setspn -s http\wcfHostMachineName:PORT DOAMIN\User
setspn -s http\wcfHostMachineName.FULLDomain.Quantifier:PORT DOAMIN\User

使用

清除客户端上的所有Kerberos-Tokens
klist -purge

试试吧。如果它有效 - &gt;精细。但是,如果没有打开你的ADS用户配置并删除所有没有端口的http-SPN,那就是wcfHost,而不是用户! wcfHost剂量需要单独的SPN。

相关问题