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

WCF信道監(jiān)聽器代碼示例解析

開發(fā) 開發(fā)工具
WCF信道監(jiān)聽器的創(chuàng)建,可以用于在某種特定模式下進(jìn)行請(qǐng)求的監(jiān)聽。那么接下來(lái)我們將會(huì)通過(guò)一段代碼示例來(lái)為大家詳細(xì)講解相關(guān)內(nèi)容。

WCF是一個(gè)功能比較強(qiáng)大的開發(fā)工具,可以幫助我們創(chuàng)建一個(gè)功能穩(wěn)定,安全性高的解決方案。在這里,我們創(chuàng)建一個(gè)自定義的信道監(jiān)聽器:SimpleReplyChannelListner。#t#

該WCF信道監(jiān)聽器用于在請(qǐng)求-回復(fù)消息交換模式下進(jìn)行請(qǐng)求的監(jiān)聽。在本案例中,我們來(lái)創(chuàng)建與之相對(duì)的信道工廠:SimpleChannelFactory< TChannel>,用于請(qǐng)求-回復(fù)消息交換模式下進(jìn)行用于請(qǐng)求發(fā)送信道的創(chuàng)建。由于SimpleChannelFactory< TChannel>的實(shí)現(xiàn)相對(duì)簡(jiǎn)單,將所有代碼一并附上。

SimpleChannelFactory< TChannel>直接繼承自抽象基類SimpleChannelFactoryBase< TChannel>。字段成員_innerChannelFactory表示信道工廠棧中后一個(gè)信道工廠對(duì)象,該成員在構(gòu)造函數(shù)中通過(guò)傳入的BindingContext對(duì)象的BuildInnerChannelFactory< TChannel>方法創(chuàng)建。OnCreateChannel是核心大方法,實(shí)現(xiàn)了真正的信道創(chuàng)建過(guò)程,在這里我們創(chuàng)建了我們自定義的信道:SimpleRequestChannel.。構(gòu)建SimpleRequestChannel. 的InnerChannel通過(guò)­­­_innerChannelFactory的CreateChannel方法創(chuàng)建。對(duì)于其他的方法(OnOpen、OnBeginOpen和OnEndOpen),我們僅僅通過(guò)PrintHelper輸出當(dāng)前的方法名稱,并調(diào)用­_innerChannelFactory相應(yīng)的方法。

WCF信道監(jiān)聽器代碼示例:

 

  1. public class SimpleChannelFactory< TChannel> : 
    ChannelFactoryBase
    < TChannel> 
  2. {  
  3. public IChannelFactory< TChannel> _innerChannelFactory;  
  4. public SimpleChannelFactory(BindingContext context)  
  5. {  
  6. PrintHelper.Print(this, "SimpleChannelFactory");  
  7. this._innerChannelFactory = context.BuildInnerChannelFactory
    < TChannel>();  
  8. }   
  9. protected override TChannel OnCreateChannel
    (EndpointAddress address, Uri via)  
  10. {  
  11. PrintHelper.Print(this, "OnCreateChannel");  
  12. IRequestChannel innerChannel = this._innerChannelFactory.
    CreateChannel(address, via) as IRequestChannel;  
  13. SimpleRequestChannel. channel = new SimpleRequestChannel.
    (this, innerChannel);  
  14. return (TChannel)(object)channel;  
  15. }  
  16. protected override IAsyncResult OnBeginOpen
    (TimeSpan timeout, AsyncCallback callback, object state)  
  17. {  
  18. PrintHelper.Print(this, "OnBeginOpen");  
  19. return this._innerChannelFactory.BeginOpen(timeout, callback, state);  
  20. }   
  21. protected override void OnEndOpen(IAsyncResult result  
  22. {  
  23. PrintHelper.Print(this, "OnEndOpen");  
  24. this._innerChannelFactory.EndOpen(result);  
  25. }  
  26. protected override void OnOpen(TimeSpan timeout)  
  27. {  
  28. PrintHelper.Print(this, "OnOpen");  
  29. this._innerChannelFactory.Open(timeout);  
  30. }  

以上就是對(duì)WCF信道監(jiān)聽器的相關(guān)介紹。

責(zé)任編輯:曹凱 來(lái)源: 博客園
相關(guān)推薦

2009-11-09 10:03:09

WCF通道監(jiān)聽器

2010-02-24 13:38:18

WCF PreCal模

2010-02-22 15:00:02

WCF信道工廠

2011-03-21 16:21:49

Oracle監(jiān)聽口令監(jiān)聽器

2009-07-08 17:39:23

Servlet監(jiān)聽器

2009-09-27 17:46:22

Hibernate監(jiān)聽

2011-05-16 10:14:11

Hibernate

2011-06-01 14:55:24

Android Service 監(jiān)聽器

2010-04-23 18:00:31

2009-07-06 13:48:53

Servlet監(jiān)聽器

2010-01-13 09:49:09

注釋監(jiān)聽器Listener

2009-01-03 13:37:26

Oracle監(jiān)聽器Oracle服務(wù)器Oracle網(wǎng)絡(luò)配置

2009-11-18 18:28:27

Oracle監(jiān)聽器

2010-03-02 14:41:00

WCF行為控制

2023-01-06 08:55:00

2012-02-03 13:27:16

2010-08-09 11:06:01

Flex事件機(jī)制

2010-04-19 15:38:10

2010-04-23 10:13:18

Oracle監(jiān)聽

2020-04-20 11:09:49

過(guò)濾器監(jiān)聽器 Web
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)