[WCF安全系列]绑定、安全模式与客户端凭证类型:NetNamedPipeBinding、NetTcpBinding与NetMsmqBinding

简介:

在前面两篇(《绑定、安全模式与客户端凭证类型:BasicHttpBinding》和《绑定、安全模式与客户端凭证类型:WSHttpBinding与WSDualHttpBinding》)中,我们详细地介绍了四种基于HTTP的绑定分别支持的安全模式,已经在相应的安全模式下可以采用怎样的客户端凭证。在本篇文章中,我们安全线相同的方式来介绍三种基于局域网的绑定,即NetNamedPipeBinding、NetTcpBinding与 NetMsmqBinding。

一、NetNamedPipeBinding

NetNamedPipeBinding只能用于同一台机器上的不同进程之间的通信(IPC:Inter-Process Communication)。在IPC这样的通信场景下,根本不需要基于Message模式的安全。所以在表示NetNamedPipeBinding安全的NetNamedPipeSecurity类型中,表示支持的安全模式的Mode属性对应的NetNamedPipeSecurityMode枚举仅仅具有两个选项:None和Transport。在默认的情况下,NetNamedPipeBinding采用Transport安全模式。

此外还有一点值得一提:表示Transport模式安全的NamedPipeTransportSecurity类并不存在ClientCredentialType属性,因为它总是采用Windows作为其客户端凭证。NetNamedPipeBinding安全相关的应用编程接口如下面的代码片断所示。

   1: public class NetNamedPipeBinding : Binding, IBindingRuntimePreferences
   2: {
   3:     //其他成员
   4:     public NetNamedPipeSecurity Security { get; set; }
   5: }
   6: public sealed class NetNamedPipeSecurity
   7: {
   8:     //其他成员
   9:     public NetNamedPipeSecurityMode Mode { get; set; }
  10:     public NamedPipeTransportSecurity Transport { get; set; }
  11: }
  12: public enum NetNamedPipeSecurityMode
  13: {
  14:     None,
  15:     Transport
  16: }
  17: public sealed class NamedPipeTransportSecurity
  18: {
  19:    //不存在ClientCredentialType属性
  20: }

二、NetTcpBinding

较之NetNamedPipeBinding,NetTcpBinding涉及安全相关的定义就要复杂一些。Security属性返回的是一个用于设置NetTcpBinding安全的NetTcpSecurity对象。表示安全模式的NetTcpSecurity的Mode属性返回的是我们提到过的SecurityMode枚举,意味着NetTcpSecurity和WSHttpBinding以及WS2007HttpBinding支持相同的安全模式集,即None、Transport、Message和Mixed(TransportWithMessageCredential)。在默认的情况下,NetTcpBinding采用Transport安全模式

NetTcpSecurity的Transport属性返回的是一个用于进行Transport安全设置的TcpTransportSecurity类型对象。TcpTransportSecurity的ClientCredentialType属性以TcpClientCredentialType枚举的形式表示采用的客户端凭证类型。定义在TcpClientCredentialType中的三个枚举值表示NetTcpBinding在Transport模式下支持的所有客户端凭证类型:None、Windows和Certificate。在默认的情况下,NetTcpBinding采用Windows凭证

而通过Message属性返回的用于进行Message安全设置的则是一个MessageSecurityOverTcp类型对象。MessageSecurityOverTcp用于表示客户端凭证类型的ClientCredentialType属性的依然是MessageCredentialType,意味着NetTcpBinding和上述的三个WS绑定在Message模式下,具有相同的客户端凭证集。在默认的情况下,NetTcpBinding采用Windows凭证。NetTcpBinding安全相关的应用编程接口如下面的代码片断所示。

   1: public class NetTcpBinding : Binding, IBindingRuntimePreferences
   2: {
   3:     //其他成员
   4:     public NetTcpSecurity Security { get;set}
   5: }
   6: public sealed class NetTcpSecurity
   7: {  
   8:     //其他成员
   9:     public SecurityMode Mode {  get; set; }
  10:     public TcpTransportSecurity Transport { get;  set; }
  11:     public MessageSecurityOverTcp Message { get; set; }
  12: }
  13: public sealed class TcpTransportSecurity
  14: {    
  15:     //其他成员
  16:     public TcpClientCredentialType ClientCredentialType { get; set; }
  17: }
  18: public sealed class MessageSecurityOverTcp
  19: {    
  20:     //其他成员
  21:     public MessageCredentialType ClientCredentialType { get; set; }
  22: }
  23: public enum TcpClientCredentialType
  24: {
  25:     None,
  26:     Windows,
  27:     Certificate
  28: }

三、NetMsmqBinding

NetMsmqBinding的Security属性的类型为NetMsmqSecurity。而表示NetMsmqBinding采用的安全模式的Mode属性返回一个NetMsmqSecurityMode枚举。NetMsmqSecurityMode枚举的定义反映了NetMsmqBinding支持的安全模式集与其它系统定义绑定都不太一样。定义在NetMsmqSecurityMode的四个枚举值反映了NetMsmqBinding支持的四种安全模式:None、Transport、Message和Both。

首先,NetMsmqBinding具有 一种独有的安全模式Both。这种模式意味中同时采用Transport和Message,就像是加上了双保险。有人可能会提出这样的问题:如果同时采用Transport和Message两种模式,性能岂不是会变得很差?但是,由于MSMQ总是采用一种单向(One-Way)或者异步的消息发送机制,对性能并没有太高的要求。此外,NetMsmqBinding并不支持Mixed(TransportWithMessageCredential)。在默认的情况下,NetMsmqBinding采用Transport安全模式

通过NetMsmqSecurity的Transport属性返回的用于进行Transport安全设置的是一个类型为MsmqTransportSecurity的对象。和NetNamedPipeBinding类似,MsmqTransportSecurity并没有一个ClientCredentialType属性。这是因为在Transport模式下,NetMsmqBinding总是采用Windows凭证。而通过用于进行Message安全设置的Message属性对应的类型为MessageSecurityOverMsmq。MessageSecurityOverMsmq具有一个类型为MessageCredentialType的ClientCredentialType属性。NetMsmqSecurity安全相关的应用编程接口定义反映在下面的代码片断中。

   1: public class NetMsmqBinding : MsmqBindingBase
   2: {    
   3:     //其他成员
   4:     public NetMsmqSecurity Security {get; set; }
   5: } 
   6: public sealed class NetMsmqSecurity
   7: {    
   8:     //其他成员
   9:     public NetMsmqSecurityMode Mode {  get; set; }
  10:     public MsmqTransportSecurity Transport { get; set; }
  11:     public MessageSecurityOverMsmq Message { get; set; }
  12: }
  13: public enum NetMsmqSecurityMode
  14: {
  15:     None,
  16:     Transport,
  17:     Message,
  18:     Both
  19: }
  20: public sealed class MsmqTransportSecurity
  21: {
  22:     //不存在ClientCredentialType属性
  23: }
  24:  
  25: public sealed class MessageSecurityOverMsmq
  26: {
  27:     //其他成员
  28:     public MessageCredentialType ClientCredentialType {get; set; }
  29:  }

作者:蒋金楠
微信公众账号:大内老A
微博: www.weibo.com/artech
如果你想及时得到个人撰写文章以及著作的消息推送,或者想看看个人推荐的技术资料,可以扫描左边二维码(或者长按识别二维码)关注个人公众号(原来公众帐号 蒋金楠的自媒体将会停用)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
相关文章
|
网络协议 安全 Windows
WCF如何绑定netTcpBinding寄宿到控制台应用程序详解
新建一个WCF服务类库项目,在其中添加两个WCF服务:GameService,PlayerService
WCF如何绑定netTcpBinding寄宿到控制台应用程序详解
|
安全 网络协议 网络安全
WCF安全3-Transport与Message安全模式
WCF安全3-Transport与Message安全模式
123 0
WCF安全3-Transport与Message安全模式
|
存储 算法 安全
WCF安全2-非对称加密
WCF安全2-非对称加密
153 0
WCF安全2-非对称加密
|
安全 数据安全/隐私保护
WCF安全1-开篇
WCF安全1-开篇
123 0
WCF安全1-开篇
|
网络协议
WCF绑定的选择
版权声明:欢迎评论和转载,转载请注明来源。 https://blog.csdn.net/zy332719794/article/details/8593924 格式与编码 每种标准绑定使用的传输协议与编码格式都不相同,如表1-1 所示。
613 0
|
XML 安全 网络协议
WCF入门(一)——终结点,地址,绑定(1)
运行WCF服务 这里通过自宿主方式self-host来运行wcf服务。 公开终结点Endpoint,终结点由ServiceEndpoint 类来实现。它有很多的成员。其中要用到的是所说的ABC。 Address,Binding,Contract,地址,绑定,契约。
1027 0
WCF绑定细节(2)——绑定,绑定元素
绑定这块引出了很多细节。绑定解决了消息交换中的传输协议,传输,编码等问题。如果要公开WCF服务,就要公开终结点Endpoint,WCF服务信息交换就是Endpoint之间的信息交换。终结点三大元素:ABC。
873 0
|
安全 网络架构
消息(7)——WCF编程模型中控制消息(1)绑定,契约
WCF服务要通过终结点来进行通信,终结点三大构成元素:ABC,其中的B,binding是重中之重,它解决了在消息交换过程中的编码,传输协议,安全等问题。 绑定是分层的,一个绑定对象对应一组有序的绑定元素的集合。
762 0
|
前端开发
WCF更新服务引用报错的原因之一
WCF更新服务引用报错的原因之一
|
C# 数据安全/隐私保护
c#如何创建WCF服务到发布(SqlServer版已经验证)
c#如何创建WCF服务到发布(SqlServer版已经验证)
64 0