[英]Disable certification validation on client side of wcf
我在IIS中運行了2個應用程序 - 客戶端和服務。 服務運行得很好,但客戶端不是。
他們通過WCF互相交談,並在證書上傳遞消息安全性(這不是傳輸安全性,而只是消息安全性)。 兩者都使用自簽名證書。
但是客戶端最終會出錯:
System.IdentityModel.Tokens.SecurityTokenValidationException:X.509證書...不在受信任的人員存儲中。 X.509證書......連鎖建築失敗。 使用的證書具有無法驗證的信任鏈。 替換證書或更改certificateValidationMode。 已處理證書鏈,但終止於信任提供程序不信任的根證書
我知道如何在服務端禁用證書驗證,我做到了,但是如何在客戶端禁用CA驗證?
如果要從客戶端應用程序向服務器發出請求,請在發出服務請求之前調用以下行以避免進行認證檢查。
使用此代碼將繞過由於自簽名證書而導致的SSL驗證錯誤。
System.Net.ServicePointManager.ServerCertificateValidationCallback =
delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
注意:僅用於測試目的,實際應用程序使用有效的SSL證書。
sudhAnsu63提供的解決方案應該適合您。
或者,由於您使用的是Message
安全性,因此可以將其添加到客戶端配置文件中:
<serviceCertificate>
<authentication certificateValidationMode="None" />
</serviceCertificate>
在代碼中使用此:
using System.ServiceModel; // (to ChannelFactory)
using System.IdentityModel;
ConfigChannel = new ChannelFactory<xxxxxx>(binding, endPoint);
ConfigChannel.Credentials.UserName.UserName = _userName;
ConfigChannel.Credentials.UserName.Password = _password;
ConfigChannel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
如果您在“受信任的根證書頒發機構”中調整自簽名證書,則可以避免證書錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.