如何使用wcf中的用户名令牌配置文件向soap标头添加加密

时间:2010-10-27 16:41:16

标签: wcf encryption wcf-client usernametoken

我有一个使用WCF工作的USername令牌配置文件,我试图在客户端调用上添加对加密的支持,webservice期望加密的soap头。我使用MMC在我的本地商店中安装了证书。在我的下面的c#代码中,我有代码加载证书并将其分配给代理。我不确定我的自定义绑定中需要的其他设置或我的c#代码中缺少的是什么。有什么建议?

的app.config:

<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();

1 个答案:

答案 0 :(得分:1)

虽然soap请求can be encrypted,但它不是HTTPS的替代品。 HTTPS比SOAP提供的更容易实现并提供更好的安全性。

相关问题