日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WCF信道監(jiān)聽器代碼示例解析

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

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

SimpleChannelFactory< TChannel>直接繼承自抽象基類SimpleChannelFactoryBase< TChannel>。字段成員_innerChannelFactory表示信道工廠棧中后一個信道工廠對象,該成員在構(gòu)造函數(shù)中通過傳入的BindingContext對象的BuildInnerChannelFactory< TChannel>方法創(chuàng)建。OnCreateChannel是核心大方法,實現(xiàn)了真正的信道創(chuàng)建過程,在這里我們創(chuàng)建了我們自定義的信道:SimpleRequestChannel.。構(gòu)建SimpleRequestChannel. 的InnerChannel通過---_innerChannelFactory的CreateChannel方法創(chuàng)建。對于其他的方法(OnOpen、OnBeginOpen和OnEndOpen),我們僅僅通過PrintHelper輸出當前的方法名稱,并調(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. protected override TChannel OnCreateChannel
    (EndpointAddress address, Uri via)
  9. {
  10. PrintHelper.Print(this, "OnCreateChannel");
  11. IRequestChannel innerChannel = this._innerChannelFactory.
    CreateChannel(address, via) as IRequestChannel;
  12. SimpleRequestChannel. channel = new SimpleRequestChannel.
    (this, innerChannel);
  13. return (TChannel)(object)channel;
  14. }
  15. protected override IAsyncResult OnBeginOpen
    (TimeSpan timeout, AsyncCallback callback, object state)
  16. {
  17. PrintHelper.Print(this, "OnBeginOpen");
  18. return this._innerChannelFactory.BeginOpen(timeout, callback, state);
  19. protected override void OnEndOpen(IAsyncResult result
  20. {
  21. PrintHelper.Print(this, "OnEndOpen");
  22. this._innerChannelFactory.EndOpen(result);
  23. }
  24. protected override void OnOpen(TimeSpan timeout)
  25. {
  26. PrintHelper.Print(this, "OnOpen");
  27. this._innerChannelFactory.Open(timeout);
  28. }
  29. }

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


標題名稱:WCF信道監(jiān)聽器代碼示例解析
網(wǎng)站URL:http://www.5511xx.com/article/djcjgss.html