[英]WCF certificates not being set on custom credentials
我在WCF中有一個ClientCredentials的自定義實現。 ClientCredentials的兩個基本屬性是ClientCertificate和ServiceCertificate,如此處所示(MSDN) 。
在我的配置中,我設置了自定義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%使用UserName身份驗證。 它使用證書對消息的用戶名和密碼進行加密。 然后,我更改為自定義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();
刪除舊憑證並添加我自己的自定義憑證。 但是,這是在創建沒有設置證書的新實例! 哎呀!
為了將其標記為已回答,我添加了自己的解決方案,該解決方案是從客戶端中刪除此代碼以生成新的憑據:
this.ChannelFactory.Endpoint.Behaviors.Remove<ClientCredentials>();
this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials());
並使用WCF已設置的那個,而不是對其調用Remove()。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.