Welcome

首页 / 软件开发 / WCF / WCF示例(15) - 可靠性消息(ReliableMessaging)

WCF示例(15) - 可靠性消息(ReliableMessaging)2012-01-20 webabcd 介绍

WCF(Windows Communication Foundation) - 可靠性消息(ReliableMessaging):

·通过重试的方法来保证消息的可靠传递,默认为8次

·当配置了“有序传递”的时候,客户端和服务端会开辟缓冲区,服务端缓冲区在接到所有客户端发来的消息后,按照客户端调用的顺序排序各个消息,然后有序地调用服务端

示例

1、服务

IReliable.cs

using System;using System.Collections.Generic;using System.Linq;using System.Text;  using System.ServiceModel;  namespace WCF.ServiceLib.Message{  /**//// <summary>  /// 演示可靠性消息的接口  /// </summary>  /// <remarks>  /// DeliveryRequirements - 指定绑定必须提供给服务或客户端实现的功能要求  /// RequireOrderedDelivery - 如果指示 WCF 确认绑定必须支持排序消息,则为 true;否则为 false。默认值为 false。如果设置为了 true,那么也需要在配置的时候将order设置为 true  /// </remarks>  [ServiceContract]  [DeliveryRequirements(RequireOrderedDelivery = true)]  public interface IReliable  {    /**//// <summary>    /// 将字符串写入文本文件    /// </summary>    /// <param name="str">需要写入文本文件的字符串</param>    [OperationContract(IsOneWay = true)]    void Write(string str);  }}