學(xué)習(xí)筆記教你使用WCF生成代理
在編程中現(xiàn)在有一個(gè)詞代理,想必大家也都知道,下面我們就WCF生成代理和大家分析一下。對于一個(gè)好的分布式系統(tǒng)來講,設(shè)計(jì)時(shí)應(yīng)當(dāng)考慮到異構(gòu)性、開放性、安全性、可擴(kuò)展性、故障處理、并發(fā)性以及透明性等問題?;赟OAP的Web Service可以實(shí)現(xiàn)異構(gòu)環(huán)境的互操作性,保證了跨平臺的通信。
#T#利用WSE(Web Service Enhancements)可以為ASMX提供安全性的保證。.NET Remoting具有豐富的擴(kuò)展功能,可以創(chuàng)建定制的信道、格式化器和代理程序。Enterprise Service(COM+)提供了對事務(wù)的支持,其中還包括分布式事務(wù),可實(shí)現(xiàn)故障的恢復(fù)。MSMQ可以支持異步調(diào)用、脫機(jī)連接、斷點(diǎn)連接等功能,利用消息隊(duì)列支持應(yīng)用程序之間的消息傳遞。從功能角度來看,WCF整合了ASMX、.Net Remoting、Enterprise Service、WSE以及MSMQ等現(xiàn)有技術(shù)的優(yōu)點(diǎn),它提供了一種構(gòu)建安全可靠的分布式面向服務(wù)系統(tǒng)的統(tǒng)一的框架模型,使軟件研發(fā)人員在開發(fā)分布式應(yīng)用時(shí)變得更加輕松。
(1)WCF生成代理類
- publicpartialclassSearchApplicationAdminWebServiceClient:System.ServiceModel.ClientBase<ISearchApplicationAdminWebService>,
ISearchApplicationAdminWebService- {
- publicSearchApplicationAdminWebServiceClient()
- {
- InspectorBehaviormessageInspectorBehavior=base.ChannelFactory.Endpoint.Behaviors.Find<InspectorBehavior>();
- if(messageInspectorBehavior==null)
- {
- base.ChannelFactory.Endpoint.Behaviors.Add(newInspectorBehavior());
- }
- }
- ....
- }
(2)WCF生成代理利用channelFactory
- ChannelFactory<ISearchApplicationAdminWebService>channelFactory=newChannelFactory<ISearchApplicationAdminWebService>
("CustomBinding_ISearchApplicationAdminWebService");- InspectorBehaviormessageInspectorBehavior=channelFactory.Endpoint.Behaviors.Find<InspectorBehavior>();
- if(messageInspectorBehavior==null)
- {
- channelFactory.Endpoint.Behaviors.Add(newInspectorBehavior());
- }
- varserver=channelFactory.CreateChannel();