深入理解WCF配置可靠性

开发 后端
我们在编程中可以支持它的绑定WCF配置可靠性,文章有一个启用TCP绑定的可靠性,希望对大家有帮助。

WCF还是比较常用的,于是我研究了一下WCF配置可靠性,在这里拿出来和大家分享一下,希望对大家有用。通过编程方式或管理方式都可以WCF配置可靠性(以及有序传递)。如果我们启用了可靠性,则客户端与服务宿主端必须保持一致,否则客户端无法与服务通信。我们可以只对支持它的绑定WCF配置可靠性。例所示的服务端配置文件,使用了绑定配置节,启用了TCP绑定的可靠性。

例:启用TCP绑定的可靠性

<system.serviceModel> 
<services> 
<service name = "MyService"> 
<endpoint 
address  = "net.tcp://localhost:8000/MyService" 
binding  = "netTcpBinding" 
bindingConfiguration = "ReliableTCP" 
contract = "IMyContract"/> 
</service> 
</services> 
<bindings> 
<netTcpBinding> 
<binding name = "ReliableTCP"> 
<reliableSession enabled = "true"/> 
</binding> 
</netTcpBinding> 
</bindings> 
</system.serviceModel> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

至于编程配置方式,TCP绑定和WS绑定提供了略微不同的属性来WCF配置可靠性。例如,NetTcpBinding绑定接受一个Boolean型的构造函数参数,用来启动可靠性:

public class NetTcpBinding : Binding,...  
{  
public NetTcpBinding(...,bool reliableSessionEnabled);  
//更多成员  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

我们只能在对象的构造期间启用可靠性。如果通过编程方式设置可靠性,需要创建支持可靠性的绑定对象:

Binding reliableTcpBinding = new NetTcpBinding(...,true);  
NetTcpBinding定义了只读的ReliableSession类,通过它获取可靠性的状态:  
public class ReliableSession  
{  
public TimeSpan InactivityTimeout  
{get;set;}  
public bool Ordered  
{get;set;}  
//更多成员  
}  
public class OptionalReliableSession : ReliableSession  
{  
public bool Enabled  
{get;set;}  
//更多成员  
}  
public class NetTcpBinding : Binding,...  
{  
public OptionalReliableSession ReliableSession  
{get;}  
//更多成员  
}  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

#T#理论上,服务代码和契约定义应该与它使用的绑定及属性无关。服务不应该考虑绑定,在服务代码中也不应该包含它所使用的绑定。不管配置的绑定是哪一种,服务都应该能够正常工作。然而实际上,服务的实现或者契约本身都会依赖于消息的有序传递(Ordered Delivery)。为了帮助契约或服务的开发者能够约束支持的绑定,WCF定义了DeliveryRequirementsA。

责任编辑:田树 来源: 博客
相关推荐

2009-11-05 16:45:52

WCF可靠性传输

2010-03-02 18:16:45

WCF可靠性传输

2009-11-06 09:14:14

WCF可靠性

2010-12-28 19:50:21

可靠性产品可靠性

2009-06-19 14:10:42

Java多态性

2011-05-25 19:31:07

Stratus信息化

2010-12-28 20:16:24

2019-08-30 12:10:05

磁盘数据可靠性RAID

2020-07-21 08:26:08

SpringSecurity过滤器

2016-12-08 15:36:59

HashMap数据结构hash函数

2010-06-01 15:25:27

JavaCLASSPATH

2009-04-08 10:23:00

软交换网络可靠

2010-12-28 19:55:20

软件架构可靠性

2024-05-09 08:04:23

RabbitMQ消息可靠性

2013-11-04 17:04:22

容错可靠

2020-12-06 14:51:23

物联网可靠性IOT

2017-06-23 18:25:51

kafka数据可靠性

2024-07-04 12:36:50

2025-03-03 03:00:00

2010-12-28 20:04:10

网络的可靠性网络解决方案可靠性
点赞
收藏

51CTO技术栈公众号