WCF雙工會話通道基本創建步驟詳解
WCF開發插件擁有非常大的功能優勢,這些優勢決定了其在開發領域中占據著一定的主導地位。我們今天就先從WCF雙工會話通道的基本概念開始了解,來對這一開發工具進行更加深入的了解。
從對象模型的角度來看,會話通道形狀與非會話通道只有一些細微的差別。例如,IDuplexSessionChannel是IDuplexChannel和 ISessionChannel<IDuplexSession>的結合體。因為我們已有有了一個DelegatorDuplexChannel類型定義(它實現了IDuplexChannel接口),創建一個WCF雙工會話通道僅僅是一個繼承DelegatorDuplexChannel并實現IDuplexSessionChannel接口的問題,如下所示:
- internal sealed class DelegatorDuplexSessionChannel :
DelegatorDuplexChannel, IDuplexSessionChannel- {
- private IDuplexSessionChannel _innerSessionChannel;
- // reference the next
- // sessionful channel
- private String _source;
- // store the String to output internal
- DelegatorDuplexSessionChannel(ChannelManagerBase
- channelManagerBase, IDuplexSessionChannel innerChannel, String source)
: base(channelManagerBase, innerChannel, source)- {
- _source = String.Format("{0} CHANNEL: DelegatorDuplexSessionChannel",
source);- PrintHelper.Print(_source, "ctor");
- // assign the reference to the next sessionful channel
- this._innerSessionChannel = innerChannel;
- }
- // IDuplexSessionChannel member that is not defined in IDuplexChannel
- public IDuplexSession Session
- {
- get {
- PrintHelper.Print(_source, "Session");
- return this._innerSessionChannel.Session;
- }
- }
- }
DelegatorDuplexChannel包含一個IDuplexChannel類型的成員變量,我們需要通過一個IDuplexSessionChannel類型的局部變量來存儲同一個對象的引用。這樣做可以使得我們容易地添加Session屬性到我們的類型定義上。
以上就是對WCF雙工會話通道的相關介紹。
【編輯推薦】