標籤:style blog http color io ar 資料 div sp
1.產生認證 makecert -sr localmachine -ss My -n CN=WCFServer -sky exchange -pe -r
2.ssl認證設定
httpcfg: 1.httpcfg query ssl
2.httpcfg set ssl -i 0.0.0.0:port -h hash
netsh:
1. netsh http show sslcert
2. netsh http add sslcert ipport=0.0.0.0:port certhash=hash appid={GUID}
hash:認證的指紋
GUID:調用的應用程式的GUID
httpcfg:XP/2003/win8
netsh:vist/win7/win8
個人覺得win8下用netsh比較好 記得管理員權限
3.服務端配置
1.綁定
設定綁定的安全模式為通道安全
<security mode="Transport">
客戶類型憑證為基本
<transport clientCredentialType="Basic"></transport>
2.基地址
基地址為https開頭
<add baseAddress = "https://127.0.0.1:3555/TractabilityWCFServiceLib/Service1/" />
3.終結點
設定支援https的繫結模式、配置綁定
<endpoint address ="" binding="wsHttpBinding" contract="TractabilityWCFInface.IService1" bindingConfiguration="wsHttps"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
4.設定服務行為
設定中繼資料終結點為https
<serviceMetadata httpsGetEnabled="True"/>
設定服務憑證
1.服務端為認證驗證
<serviceCertificate x509FindType="FindBySubjectName" storeName="My" storeLocation="LocalMachine" findValue="WcfServerPK"/>
2.客戶認證的身分識別驗證為none
<clientCertificate> <authentication certificateValidationMode="None"/></clientCertificate>
3.使用者名稱密碼身分識別驗證為自訂 指定驗證類
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="命名空間.類名,程式集"/>
5.自訂使用者名稱密碼驗證類
繼承 System.IdentityModel.Selectors.UserNamePasswordValidator
實現 Validate(string userName, string password)
public override void Validate(string userName, string password) { Console.WriteLine("username=" + userName);//用戶端傳來的使用者名稱 Console.WriteLine("password=" + password);//用戶端傳來的密碼 }
4.用戶端配置
1.信任認證
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback; private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
2.傳入使用者名稱、密碼
client.ClientCredentials.UserName.UserName = "admin"; client.ClientCredentials.UserName.Password = "1231313";
wcf 認證+ssl+自訂使用者名稱密碼