自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何對WCF綁定元素進行自定義操作

開發(fā) 開發(fā)工具
如何才只能自定義我們的WCF綁定元素呢?我們今天將會通過這篇文章中介紹的簡單示例來為大家詳細講解這方面的應用技巧。

WCF開發(fā)插件在開發(fā)領域中占據(jù)著重要的位置。它可以幫助開發(fā)人員輕松的實現(xiàn)一個安全性高及可跨平臺的企業(yè)級解決方案。接下來,我們通過一個案例來演示如果自定義一個WCF綁定元素。通過該綁定元素來創(chuàng)建我們在上面一個案例中創(chuàng)建的兩個自定義信道管理器:SimpleChannelFactory和SimpleChannelListener。按照上面的命名方式,我們把這個自定義綁定元素命名為:SimpleBindingElement,下面是整個SimpleBindingElement的定義:

  1. public class SimpleBindingElement : BindingElement   
  2. {   
  3. public SimpleBindingElement()   
  4. {   
  5. PrintHelper.Print(this, "SimpleBindingElement");   
  6. }   
  7. public override BindingElement Clone()   
  8. {   
  9. PrintHelper.Print(this, "Clone");   
  10. return new SimpleBindingElement();   
  11. }   
  12. public override T GetProperty< T>(BindingContext context)   
  13. {   
  14. PrintHelper.Print(this, string.Format("GetProperty< {0}>",
     typeof(T).Name));   
  15. return context.GetInnerProperty< T>();   
  16. }   
  17. public override IChannelFactory< TChannel> BuildChannelFactory
    < TChannel>(BindingContext context)   
  18. {   
  19. PrintHelper.Print(this, "BuildChannelFactory< TChannel>");   
  20. return new SimpleChannelFactory< TChannel>(context) as 
    IChannelFactory
    < TChannel>;   
  21. }   
  22. public override IChannelListener< TChannel> BuildChannelListener
    < TChannel>(BindingContext context)   
  23. {   
  24. PrintHelper.Print(this, "BuildChannelListener< TChannel>");   
  25. return new SimpleChannelListener< TChannel>(context) as 
    IChannelListener
    < TChannel>;   
  26. }   

SimpleBindingElement直接繼承自抽象的基類BindingElement,對SimpleChannelFactory和SimpleChannelListener的創(chuàng)建分別實現(xiàn)在兩個被重寫的方法中:BuildChannelFactory< TChannel>和BuildChannelListener< TChannel>中。此外還重寫了兩個額外的方法:Clone和GetProperty< T>,前者用于克隆一個新的綁定元素,后一個和定義在信道、信道管理器的同名方法一樣,用于獲取基于某種類型的屬性。

WCF綁定元素的相關自定義操作方法就為大家介紹到這里。

【編輯推薦】

  1. WCF雙工會話通道基本創(chuàng)建步驟詳解
  2. WCF集合類在實際應用中特點分析
  3. WCF異步服務正確創(chuàng)建方式詳解
  4. WCF異步操作具體定義與應用
  5. WCF自定義集合類型應用注意事項探討
責任編輯:曹凱 來源: CSDN
相關推薦

2009-12-07 14:35:42

WCF異步調用

2009-11-09 16:06:53

WCF自定義集合

2019-11-19 08:04:16

JavaHashSet去重

2009-07-06 13:49:29

2010-02-25 16:27:44

WCF擴展點

2010-02-25 11:23:29

WCF返回自定義格式

2010-02-22 17:07:50

WCF綁定元素

2014-04-02 13:27:29

iOSNSArray對象

2009-08-03 16:37:49

C#異常類

2024-01-05 15:28:06

鴻蒙數(shù)據(jù)同步GlobalThis

2010-02-24 14:59:52

WCF自定義過濾器

2009-12-08 17:08:13

WCF Service

2021-07-01 11:07:49

Swift 自定義操作符

2010-03-01 09:56:21

WCF自定義集合類型

2010-03-02 18:01:07

WCF自定義消息篩選器

2011-12-05 15:02:21

Knockout

2009-09-07 22:00:15

LINQ自定義

2009-12-08 18:08:43

WCF服務

2010-03-01 15:12:53

WCF回調契約

2009-12-22 11:29:27

WCF自定義集合類型
點贊
收藏

51CTO技術棧公眾號