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

目前成都創(chuàng)新互聯(lián)公司已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、常德網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
- public class SimpleBindingElement : BindingElement
- {
- public SimpleBindingElement()
- {
- PrintHelper.Print(this, "SimpleBindingElement");
- }
- public override BindingElement Clone()
- {
- PrintHelper.Print(this, "Clone");
- return new SimpleBindingElement();
- }
- public override T GetProperty< T>(BindingContext context)
- {
- PrintHelper.Print(this, string.Format("GetProperty< {0}>",
typeof(T).Name));- return context.GetInnerProperty< T>();
- }
- public override IChannelFactory< TChannel> BuildChannelFactory
< TChannel>(BindingContext context)- {
- PrintHelper.Print(this, "BuildChannelFactory< TChannel>");
- return new SimpleChannelFactory< TChannel>(context) as
IChannelFactory< TChannel>;- }
- public override IChannelListener< TChannel> BuildChannelListener
< TChannel>(BindingContext context)- {
- PrintHelper.Print(this, "BuildChannelListener< TChannel>");
- return new SimpleChannelListener< TChannel>(context) as
IChannelListener< TChannel>;- }
- }
SimpleBindingElement直接繼承自抽象的基類BindingElement,對(duì)SimpleChannelFactory和SimpleChannelListener的創(chuàng)建分別實(shí)現(xiàn)在兩個(gè)被重寫(xiě)的方法中:BuildChannelFactory< TChannel>和BuildChannelListener< TChannel>中。此外還重寫(xiě)了兩個(gè)額外的方法:Clone和GetProperty< T>,前者用于克隆一個(gè)新的綁定元素,后一個(gè)和定義在信道、信道管理器的同名方法一樣,用于獲取基于某種類型的屬性。
WCF綁定元素的相關(guān)自定義操作方法就為大家介紹到這里。
新聞名稱:如何對(duì)WCF綁定元素進(jìn)行自定義操作
分享URL:http://m.fisionsoft.com.cn/article/dhpocgg.html


咨詢
建站咨詢
