wcf 認證+ssl+自訂使用者名稱密碼

來源:互聯網
上載者:User

標籤: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+自訂使用者名稱密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.