偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

WCF安全參數(shù)相關設置方法詳解

開發(fā) 開發(fā)工具
我們在這篇文章中為大家介紹的WCF安全參數(shù)的設置方法總共有三種,主要包括:安全方式; 消息保護;以及身份驗證等方式。

WCF是.NET Framework 3.5的重要組成部分,主要作用域通信方面。我們可以通過使用它來輕松的完成一些特定功能需求。在這里我們將會針對WCF安全參數(shù)的相關設置方法,為大家詳解有關內容。

WCF安全參數(shù)設置方法1. 安全方式

通過設置 Binding 的屬性 Security 來實現(xiàn)。

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

WCF安全參數(shù)設置方法2. 消息保護

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

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

WCF安全參數(shù)設置方法3. 身份驗證

不同的部署環(huán)境,會采取不同的選擇。在 Intranet 環(huán)境下,我們可能選擇 Windows 集成驗證方式,而在 Internet 環(huán)境下通常的方案是采取 X.509 數(shù)字證書,當然最最通用最最常見依然是用戶名/密碼。

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

代理方式:

  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<IMyContract> factory = new ChannelFactory<IMyContract>("");  
  2. factory.Credentials.Windows.ClientCredential = new NetworkCredential(...);  
  3. IMyContract client = factory.CreateChannel( );  
  4. using(client as IDisposable)  
  5. {  
  6. client.MyMethod( );  

在服務中,我們可以用 ServiceSecurityContext.Current (或者 OperationContext.Current.ServiceSecurityContext) 來獲取相關身份信息。

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

WCF安全參數(shù)的相關設置方法就為大家介紹到這里。

【編輯推薦】

  1. WCF tcpTrace實現(xiàn)功能淺析
  2. WCF單向協(xié)定基本創(chuàng)建步驟解析
  3. WCF返回自定義格式具體應用技巧詳解
  4. WCF響應服務基本應用技巧分享
  5. WCF排隊調用由NetMsmqBinding支持
責任編輯:曹凱 來源: 博客園
相關推薦

2010-02-26 17:44:51

WCF安全參數(shù)

2010-02-26 09:50:57

WCF傳輸安全機制

2010-03-01 09:19:10

WCF編碼規(guī)范

2010-02-26 16:20:56

WCF程序事務

2010-02-24 17:36:33

WCF集合數(shù)據(jù)契約

2010-02-25 13:40:17

WCF禁用安全配置

2010-03-01 16:31:58

WCF實現(xiàn)SOA

2009-12-21 17:05:59

WCF自托管宿主

2010-02-26 14:39:27

WCF服務寄宿

2010-02-24 11:22:04

WCF方法重載

2010-02-26 16:05:14

寄宿WCF服務

2010-02-24 09:28:37

WCF安全配置

2009-12-21 18:32:22

關閉WCF鏈接

2009-12-22 16:36:38

WCF重載

2010-02-23 14:48:38

WCF事件通知

2010-03-02 17:35:20

WCF服務加載

2009-12-21 13:27:45

WCF服務配置信息

2010-02-24 16:30:52

WCF常見錯誤

2010-02-26 11:22:16

LitwareHR使用

2019-04-02 08:36:12

點贊
收藏

51CTO技術棧公眾號