我有一个使用 WCF 工作的 USername 令牌配置文件,我正在尝试在客户端调用上添加对加密的支持,Web 服务需要一个加密的 soap 标头。我使用 MMC 在本地商店中安装了证书。在下面的 c# 代码中,我有加载证书并将其分配给代理的代码。我不确定我的自定义绑定中需要哪些其他设置,或者我的 c# 代码中缺少什么。有什么建议么?
应用程序配置:
<customBinding>
<binding name="cbinding">
<security authenticationMode="UserNameOverTransport" includeTimestamp="false">
<secureConversationBootstrap />
</security>
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
<endpoint address="https://localhost:8443/p6ws/services/ProjectService?wsdl"
binding="customBinding" bindingConfiguration="cbinding" contract="P6.WCF.Project.ProjectPortType"
name="ProjectServiceEndPointCfg">
</endpoint>
我的 C# 代码:
ProjectPortTypeClient proxy = new ProjectPortTypeClient("ProjectServiceCertificateEndPointCfgUT", endpointAddress);
proxy.ClientCredentials.UserName.UserName = UserName;
proxy.ClientCredentials.UserName.Password= Password;
proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
proxy.ClientCredentials.ServiceCertificate.Authentication.TrustedStoreLocation = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
// Set the certificate
proxy.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, "13 d3 6e f1 26 5e 5f 74 be f2 bb f5 57 a4 47 cf e7 1a c6 0a");
proxy.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, "13 d3 6e f1 26 5e 5f 74 be f2 bb f5 57 a4 47 cf e7 1a c6 0a");
ReadProjects readProjects = new ReadProjects();