我以前从未使用过soap服务,所以我可能做错了什么。我已经通过带有"Svcutil“的wsdl为服务生成了一个服务客户机引用。
我遵循了本指南https://learn.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.'我知道我加密了一些不该加密的东西,当我将我用旧代码发送的请求与我现在发送的请求进行比较时,我可以看到这是在securityheader中添加的:
<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的地方?
发布于 2020-03-30 08:20:36
因此,经过大量的阅读和比较,我最终发现在新一代的服务参考文件中,我没有将ProtectionLevel设置为System.Net.Security.ProtectionLevel.Sign。这可能是在旧的配置文件中硬编码的,而不是使用配置文件来设置ProtectionLevel。这就是导致服务端的服务不理解如何正确解密它的原因。
https://stackoverflow.com/questions/60886514
复制相似问题