2009-02-19 27 views
2

我在WCF中有一個自定義的ClientCredentials實現。 ClientCredentials的兩個基本屬性是ClientCertificate和ServiceCertificate,如here (MSDN)所示。未在自定義憑據上設置WCF證書

在我的配置,我有我的自定義設置ClientCredentials,和兩個證書定義:

 <endpointBehaviors> 
      <behavior name="MyCustomEndpointBehavior"> 
       <clientCredentials type="MyApp.Security.CentralAuthClientCredentials, MyApp"> 
        <clientCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /> 
        <serviceCertificate> 
         <defaultCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /> 
         <authentication certificateValidationMode="None" revocationMode="NoCheck" /> 
        </serviceCertificate> 
       </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 

這種配置是完全100%與用戶名的認證工作。它使用證書來加密消息的用戶名和密碼。然後我改爲自定義ClientCredentials。

在運行時,這裏是被我CentralAuthClientCredentials設置的屬性:

this.ClientCertificate = System.ServiceModel.Security.X509CertificateInitiatorClientCredential 
this.ClientCertificate.Certificate = null 
this.ServiceCertificate = System.ServiceModel.Security.X509CertificateRecipientClientCredential 
this.ServiceCertificate.DefaultCertificate = null 

那麼,爲什麼在配置組實際實例化對象中定義的客戶端和服務默認證書?看起來好像WCF完全忽略了XML標籤!

是否有一些代碼可以使用,也許在憑據的構造函數中,手動從配置中獲取這些證書?

感謝您的幫助!


更新

我是個白癡。我想到了。 WCF實際上是與證書正確設置創建我的實例,但在我的WCF客戶端,我有以下刪除/添加系列,我認爲我從MSDN例如複製:

this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>(); 
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials()); 
return base.Channel.MyServiceMethod(); 

刪除舊憑據並添加我自己的自定義。但是,這是一個沒有設置證書的新實例!哎呀!

+0

你可以顯示正在使用的綁定嗎? – 2009-02-22 07:01:03

回答

1

所以,我可以標記這個作爲回答,我加入我自己的解決方案,這是從,使一個新的憑證,客戶端刪除此代碼:

this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>(); 
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials()); 

和使用已經被設定的一個WCF,而不是調用它的Remove()。

相關問題