av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

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

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

該WCF信道監(jiān)聽(tīng)器用于在請(qǐng)求-回復(fù)消息交換模式下進(jìn)行請(qǐng)求的監(jiān)聽(tīng)。在本案例中,我們來(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)聽(tīng)器代碼示例:

 
 
 
  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. }

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


網(wǎng)站題目:WCF信道監(jiān)聽(tīng)器代碼示例解析
當(dāng)前URL:http://uogjgqi.cn/article/djcjgss.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流