2010-10-27 76 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

相關問題