2010-10-27 46 views
1

我有一个工作的用户名令牌配置文件使用WCF,我试图增加对客户端调用加密支持工作,web服务期待一个加密的SOAP消息头加密添加到SOAP头。我使用MMC在本地存储中安装了证书。在我的C#代码下面我有加载证书并将其分配给代理的代码。我不确定我需要什么其他设置在我的自定义绑定中,或者我在c#代码中丢失了什么。有什么建议么?如何使用用户名令牌的个人资料WCF

的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

虽然SOAP请求can be encrypted,它不是用于HTTPS的替代品。与任何SOAP可提供的相比,HTTPS更易于实现并提供更好的安全性。

+0

我是Web服务的消费者,我有一个要求,SOAP头进行加密。我已经使用HTTPS,但需要使用加密的HTTP协议才能正常工作。 – AZ49 2010-10-27 19:13:08

+0

@ user489100我发布的链接有c#代码来加密soap消息。加密的HTTP通常是HTTPS ... – rook 2010-10-27 22:03:03

+0

你有一个链接,这样使用WCF策略的任何机会呢? – AZ49 2010-10-28 13:15:17

相关问题