2

我在 .NET 4.0 下有一个 WCF 服务,它使用 WIF 3.5 和 ws2007FederationHttpBinding 绑定。目前它作为自托管服务运行(成功),但我希望它在 IIS7.5 下运行。但是我无法让它工作。

我对此没有深入的了解或经验,因此我通过简单地将适用于自托管的配置复制到 web.config 来解决此问题。它们几乎相同,除了behaviors\servicebehaviors\behavior\serviceCredentials\serviceCertificate在 IIS 托管的情况下似乎需要添加,但对于自托管则不需要(我不知道为什么)。两种服务设置的客户端配置也相同(除了端点地址)。测试自托管和 IIS 托管服务发生在同一台机器上,我已经尝试使用 VS 开发服务器、IIS Express 和常规 IIS 来测试 IIS 托管服务。客户端在同一台机器上。STS 在另一台机器上。

涉及 3 个 (x509) 证书。服务的证书和 STS 使用的签名证书,都在自签名根证书下。DefaultAppPool(托管 Web 服务的地方)可以访问这两个证书。据我所知,没有涉及 SSL。

我可以让 IIS 托管服务运行,并且可以请求元数据。当我提出实际请求时会发生错误。客户端错误似乎很笼统:

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
  An error occurred when verifying security for the message.

客户端的 svc 跟踪日志说的几乎相同。

服务器错误不会引发错误,但 svc 日志会显示:

The X.509 certificate CN=sts.public.example.com chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. The revocation function was unable to check revocation for the certificate.

System.IdentityModel.Selectors.X509CertificateChain.Build(X509Certificate2 certificate)
System.IdentityModel.Selectors.X509CertificateValidator.ChainTrustValidator.Validate(X509Certificate2 certificate)
System.IdentityModel.Selectors.X509SecurityTokenAuthenticator.ValidateTokenCore(SecurityToken token)
System.IdentityModel.Selectors.SecurityTokenAuthenticator.ValidateToken(SecurityToken token)
System.IdentityModel.Selectors.SamlSecurityTokenAuthenticator.ResolveClaimSet(SecurityToken token)
System.IdentityModel.Selectors.SamlSecurityTokenAuthenticator.ValidateTokenCore(SecurityToken token)
System.IdentityModel.Selectors.SecurityTokenAuthenticator.ValidateToken(SecurityToken token)
System.ServiceModel.Security.ReceiveSecurityHeader.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver, IList`1 allowedTokenAuthenticators, SecurityTokenAuthenticator& usedTokenAuthenticator)
System.ServiceModel.Security.ReceiveSecurityHeader.ReadToken(XmlDictionaryReader reader, Int32 position, Byte[] decryptedBuffer, SecurityToken encryptionToken, String idInEncryptedForm, TimeSpan timeout)
System.ServiceModel.Security.ReceiveSecurityHeader.ProcessEncryptedData(EncryptedData encryptedData, TimeSpan timeout, Int32 position, Boolean eagerMode, Boolean& primarySignatureFound)
System.ServiceModel.Security.ReceiveSecurityHeader.ExecuteFullPass(XmlDictionaryReader reader)
System.ServiceModel.Security.ReceiveSecurityHeader.Process(TimeSpan timeout, ChannelBinding channelBinding, ExtendedProtectionPolicy extendedProtectionPolicy)
System.ServiceModel.Security.MessageSecurityProtocol.ProcessSecurityHeader(ReceiveSecurityHeader securityHeader, Message& message, SecurityToken requiredSigningToken, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
System.ServiceModel.Security.SymmetricSecurityProtocol.VerifyIncomingMessageCore(Message& message, String actor, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
System.ServiceModel.Security.MessageSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)

sts.public.example.com 是 STS 的签名证书。我不知道在哪里放置这个 certificateValidationMode 以及为什么它应该与 IIS 不同。

身份模型有一个自定义 issuerNameRegistry 和 claimAuthorizationManager ,服务行为有 serviceAuthorizationManager ,但在错误之前甚至没有一个被击中。因此,当服务器从客户端接收到签名的令牌并且 IIS 本身以某种方式无法验证证书(疯狂的随机猜测)时,可能会发生错误。

我会给你配置文件和代码示例,但是因为我不知道究竟什么是相关的,什么不是,所以这一切都很多,但如果需要任何澄清,我会尽快添加。

我尝试尽可能关闭证书验证和吊销检查,并摆弄了许多我几乎不了解的设置,但毫无结果。这篇文章似乎有片刻的希望,但我真的不知道建议的解决方案适合哪里,并且考虑到它可能不再相关的日期。

如果有人能指出解决方案的方向和/或解释自托管和 IIS 托管服务之间的设置/配置要求的差异,那将非常有帮助。

4

0 回答 0