WCF訊息可靠性與有序傳遞

來源:互聯網
上載者:User
WCF作為一項通訊技術,必須保證傳輸的可靠性與 訊息的可靠性

傳輸可靠性:指的是點對點可靠性,確保資料包按順序到達。它不受網路等因素的影響

訊息可靠性:指提供了訊息端對端的保證,確保訊息的順序無誤。如果傳輸失敗,它還能提供重試功能自動處理網路阻塞、訊息緩衝、流量控制,根據具體情況適時調整發送訊息數。它還能通過對串連的驗證管理串連自身,並在不需要的時候清除串連 

理論上,WCF服務的實現與服務契約的定義與它使用的綁定以及屬性無關。實際上,服務處理訊息以及契約定義都可能與訊息的有序傳遞有關。在WCF中使用DeliveryRequirementsAttribute來對服務或者契約應用這種約束。

[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class, AllowMultiple=true)]
public sealed class DeliveryRequirementsAttribute : Attribute, IContractBehavior, IContractBehaviorAttribute
{
    private Type contractType;
    private QueuedDeliveryRequirementsMode queuedDeliveryRequirements;
    private bool requireOrderedDelivery;

 

如果 DeliveryRequirementsAttribute 應用於契約上,則實現此種契約的服務都應用可靠的有序傳遞的約束。如:

    [ServiceContract]

    [DeliveryRequirements(RequireOrderedDelivery = true)]
    public interface ICalculator1
    {
        [OperationContract]
        int Add(int x, int y);
    }

如果應用於實現某契約類型的服務,則只有此服務應用可靠的有序傳遞的約束。    [DeliveryRequirements(RequireOrderedDelivery = true)]

    publicclass CalculationService : ICalculator1
    {
        /**/
    }

 

如果實現契約的服務實現多個服務契約,也可以通過DeliveryRequirements指定只有支援某種契約終結點的服務才應

用這種可靠的有序傳遞的約束。如下:

 

[DeliveryRequirements(RequireOrderedDelivery = true, TargetContract = typeof (ICalculator1))]
public class CalculationService : ICalculator1, ICalculator2
{    
        /**/
}

RequireOrderedDelivery預設為False,如果在介面或者服務類上使用Delivery卻不設定,RequireOrderedDelivery

則也是不會開啟有序傳遞的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.