【发布时间】:2012-09-22 00:54:00
【问题描述】:
我想设置一个 WCF 服务,通过 HTTPS 使用 NTLM 身份验证并为消息使用证书安全性(我知道,通常 HTTPS 不需要消息加密)
我有证书在消息安全上工作,但是当我尝试使用 TransportWithMessageCredential 时,客户端抛出异常:
未处理的异常:System.ServiceModel.Security.MessageSecurityException:HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是 'Negotiate,NTLM'
IIS 配置为仅支持 Windows 身份验证、需要 SSL 和接受客户端证书,机器位于同一个 Active Directory 域中(事实上,我现在正在本地运行)
任何想法我做错了什么?
我的服务 web.config 如下所示:
<services>
<service name="ServiceHost.MyTestService" behaviorConfiguration="CertificateServiceBehavior">
<endpoint address="" binding="ws2007HttpBinding" contract="SharedLibrary.ITestService" bindingConfiguration="CertificateBindingConfig">
</endpoint>
</service>
</services>
<bindings>
<ws2007HttpBinding>
<binding name="CertificateBindingConfig">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true" />
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CertificateServiceBehavior">
<serviceCredentials>
<windowsAuthentication allowAnonymousLogons="false" />
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine" />
</clientCertificate>
<serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="server" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
我的客户 app.config 是这样的:
<client>
<endpoint address="https://server:9999/ServiceHost/TestService.svc" binding="ws2007HttpBinding"
contract="SharedLibrary.ITestService" bindingConfiguration="CertificateBindingConfig"
behaviorConfiguration="CertificateEndpointBehavior"
name="serviceEndpoint">
</endpoint>
</client>
<bindings>
<ws2007HttpBinding>
<binding name="CertificateBindingConfig">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true"/>
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CertificateEndpointBehavior">
<clientCredentials>
<windows allowNtlm="true" allowedImpersonationLevel="Impersonation"/>
<clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="client"/>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
【问题讨论】:
-
我假设您的客户端证书已在客户端的受信任证书中注册?
-
@M.Babcock 是的,它在受信任的人商店中。如果我对未经身份验证的 HTTP 端点使用消息安全性,它就可以工作。
-
您在端点地址中使用 localhost 吗?
-
@GrzegorzWilczura 尝试了 localhost 和我的机器名
-
在 Windows 身份验证的 IIS 身份验证设置中。当您右键单击并选择提供商时,是否就像从提供商列表中删除 Negotiate 一样简单? IIS 中也禁用了匿名身份验证?
标签: .net wcf x509certificate ntlm