首页 > 解决方案 > WCF 客户端到 WSE 3.0 服务异常:CWWSS7310E:XML 加密信息 [.....]

问题描述

我以前从未使用过肥皂服务,所以我可能做错了什么。我已经通过带有“Svcutil”的 wsdl 为该服务生成了一个服务客户端引用。

我已遵循本指南https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-wcf-client-to-interoperate-with-wse3-0 -services并设置自定义绑定。之后,我是来自引用的客户端,并提供了一个使用 WseSecurityAssertion.MutualCertificate10 和服务端点地址的新绑定。

然后我添加一个证书并将这些凭据添加到服务客户端:

clientProxy.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(string.Concat(xxx, yyy), GetCertificatePassword(xxx), PersistKeySet);
            clientProxy.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(xxx, "", PersistKeySet);
            clientProxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = ChainTrust;
            clientProxy.ClientCredentials.ServiceCertificate.Authentication.RevocationMode = NoCheck;

这是以前工作过的代码(但在使用 wcf 和“Svcutil”之前),我主要复制了它,但对其进行了一些重构。

当我调用 Web 服务时,我收到此错误:

System.ServiceModel.FaultException: 'CWWSS5511E: An exception occurred during the decryption of a message. The exception is CWWSS7310E: XML encryption information exists in the security header, however an inbound XML encryption configuration is not present.'

我知道我加密了我不应该加密的东西,当我将发送的请求与旧代码与我现在发送的请求进行比较时,我可以看到它已添加到安全标头中:

<e:EncryptedKey Id="_0" xmlns:e="http://www.w3.org/2001/04/xmlenc#"><e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns="http://www.w3.org/2000/09/xmldsig#"/></e:EncryptionMethod><KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">

还有一些关于密钥的信息。

我想知道代码以前没有做的我做错了什么。我找不到任何配置文件,所以我不认为这是我错过的一些配置。可以在哪里设置此加密?它是在绑定内部还是在我设置 clientCredentials 的地方?

标签: c#xmlwcfsoapwse3.0

解决方案


所以经过大量阅读和比较后,我最终发现我没有在新一代服务参考文件中将 ProtectionLevel 设置为 System.Net.Security.ProtectionLevel.Sign。这可能是在旧版本中硬编码的,而不是使用配置文件来设置保护级别。这就是导致服务端的服务不了解如何正确解密的原因。


推荐阅读