日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
WCF安全參數(shù)正確設(shè)置方式解讀

WCF開(kāi)發(fā)工具的推出,對(duì)開(kāi)發(fā)人員來(lái)說(shuō)帶來(lái)了非常不一般的使用體驗(yàn)。那么今天在這篇文章中,我們將會(huì)為大家詳細(xì)介紹一下有關(guān)WCF安全參數(shù)的正確設(shè)置方法,希望能夠?qū)τ中枰呐笥延兴鶐椭?/p>

成都創(chuàng)新互聯(lián)公司基于成都重慶香港及美國(guó)等地區(qū)分布式IDC機(jī)房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動(dòng)大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務(wù)器托管報(bào)價(jià),主機(jī)托管價(jià)格性價(jià)比高,為金融證券行業(yè)電信內(nèi)江機(jī)房,ai人工智能服務(wù)器托管提供bgp線路100M獨(dú)享,G口帶寬及機(jī)柜租用的專業(yè)成都idc公司。

1. 安全方式

通過(guò)設(shè)置 Binding 的屬性 Security 來(lái)實(shí)現(xiàn)WCF安全參數(shù)的設(shè)置。

 
 
 
  1. NetTcpBinding binding = new NetTcpBinding();  
  2. binding.Security.Mode = SecurityMode.Transport;  
  3. binding.Security.Transport.ProtectionLevel = 
    System.Net.Security.ProtectionLevel.EncryptAndSign; 

2. 消息保護(hù)

通過(guò) ServiceContractAttribute 和 OperationContractAttribute 特性的 ProtectionLevel 參數(shù)我們可以設(shè)置不同的消息保護(hù)級(jí)別。

 
 
 
  1. [ServiceContract(ProtectionLevelProtectionLevel = 
    ProtectionLevel.EncryptAndSign)]  
  2. interface IMyContract  
  3. {  
  4. ...  

3. 身份驗(yàn)證

不同的部署環(huán)境,會(huì)采取不同的選擇來(lái)進(jìn)行WCF安全參數(shù)的設(shè)置。在 Intranet 環(huán)境下,我們可能選擇 Windows 集成驗(yàn)證方式,而在 Internet 環(huán)境下通常的方案是采取 X.509 數(shù)字證書,當(dāng)然最最通用最最常見(jiàn)依然是用戶名/密碼。

以 Windows 集成驗(yàn)證為例,客戶端可以通過(guò) ClientBase.ClientCredentials 屬性向服務(wù)器端發(fā)送與其相匹配的身份驗(yàn)證信息。缺省情況下,客戶端使用當(dāng)前 Windows 登錄賬戶作為身份驗(yàn)證信息,我們也可以顯式設(shè)置不同的身份信息。

代理方式:

 
 
 
  1. NetworkCredential credentials = new NetworkCredential( );  
  2. credentials.Domain = "MyDomain";  
  3. credentials.UserName = "MyUsername";  
  4. credentials.Password = "MyPassword";  
  5. using (MyContractClient client = new MyContractClient())  
  6. {  
  7. client.ClientCredentials.Windows.ClientCredential = credentials;  
  8. client.MyMethod( );  

工廠方式:

 
 
 
  1. ChannelFactory factory = new ChannelFactory("");  
  2. factory.Credentials.Windows.ClientCredential = new NetworkCredential(...);  
  3. IMyContract client = factory.CreateChannel( );  
  4. using(client as IDisposable)  
  5. {  
  6. client.MyMethod( );  

在服務(wù)中,我們可以用 ServiceSecurityContext.Current (或者 OperationContext.Current.ServiceSecurityContext) 來(lái)獲取相關(guān)身份信息。

 
 
 
  1. Console.WriteLine(ServiceSecurityContext.Current.
    WindowsIdentity.AuthenticationType);  
  2. Console.WriteLine(ServiceSecurityContext.Current.
    WindowsIdentity.Name); 

以上就是我們介紹的WCF安全參數(shù)的設(shè)置方法。

【編輯推薦】

  1. WCF程序事務(wù)相關(guān)定義與實(shí)現(xiàn)方法詳解
  2. WCF啟用端口三步驟實(shí)現(xiàn)
  3. WCF傳送二進(jìn)制流數(shù)據(jù)基本實(shí)現(xiàn)步驟詳解
  4. 寄宿WCF服務(wù)相關(guān)實(shí)現(xiàn)方法解析
  5. WCF套接字連接中斷具體解決方法詳解

本文題目:WCF安全參數(shù)正確設(shè)置方式解讀
文章來(lái)源:http://www.5511xx.com/article/cdgphec.html