新聞中心
我們知道,在WCF中,可以實(shí)現(xiàn)許多相應(yīng)的功能,來幫助我們輕松的解決一些比較復(fù)雜的問題。在這里我們就一起來了解一下有關(guān)WCF實(shí)現(xiàn)SOA的相關(guān)方法,以方便我們在實(shí)際應(yīng)用中來獲得些幫助。#t#

成都創(chuàng)新互聯(lián)專注于曲江企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,商城開發(fā)。曲江網(wǎng)站建設(shè)公司,為曲江等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站建設(shè),專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
WCF實(shí)現(xiàn)SOA的一個關(guān)鍵問題是,如何將與技術(shù)無關(guān)的服務(wù)轉(zhuǎn)換為CLR。一旦提供了這種轉(zhuǎn)換,WCF的服務(wù)設(shè)計者與開發(fā)者就可以根據(jù)自己擁有的CLR的知識,進(jìn)行WCF面向服務(wù)開發(fā)。為兩者搭建橋梁的是宿主。一個宿主可以包含多個上下文,而在上下文中則可以包含服務(wù)實(shí)例。特殊的,宿主的上下文也可以為空。
客戶端若要調(diào)用服務(wù),可以采用代理或通道的方式。這兩種方式在很多資料上已經(jīng)有了詳盡的介紹。在這里,我不準(zhǔn)備重復(fù)。如果需要詳細(xì)了解甚至掌握著兩種方式,當(dāng)然可以購買Programming WCF Services一書一探究竟。這里我想介紹的是本書中頻繁使用的一種簡化WCF類庫的一個示例,主要是引入泛型來簡化以及各種步驟地自動化處理。例如ServiceHost
- public class ServiceHost
: ServiceHost { - public ServiceHost( ) : base(typeof(T)) {}
- public ServiceHost(params string[] baseAddresses) :
base(typeof(T),Convert(baseAddresses)) {}- public ServiceHost(params Uri[] baseAddresses) :
base(typeof(T),baseAddresses) {}- static Uri[]
- Convert(string[] baseAddresses) {
- Converter
convert = delegate(string address)
{ return new Uri(address); };- return Array.ConvertAll(baseAddresses,convert);
- } }
如果是使用ServiceHost類,則托管服務(wù)的代碼如下所示:
- public static void Main( ) {
- Uri baseAddress = new Uri("http://localhost:8000/");
- ServiceHost host = new ServiceHost(typeof(MyService),baseAddress);
- host.Open( );
- //Can do blocking calls: Application.Run(new MyForm( ));
- host.Close( );
- }
使用ServiceHost類,則可修改為:
- public static void Main( ) {
- Uri baseAddress = new Uri("http://localhost:8000/");
- ServiceHost
host = new ServiceHost (baseAddress); - host.Open( );
- //Can do blocking calls:
- Application.Run(new MyForm( ));
- host.Close( );
- }
在ServiceHost
- public static TOutput[]
- ConvertAll
( TInput[] array,
Converterconverter )
它能夠根據(jù)Converter對象將一種類型的數(shù)組轉(zhuǎn)換為另一種類型的數(shù)組。
以上就是對WCF實(shí)現(xiàn)SOA的相關(guān)步驟的介紹。
分享名稱:WCF實(shí)現(xiàn)SOA相關(guān)操作步驟詳解
鏈接URL:http://m.fisionsoft.com.cn/article/cdegpip.html


咨詢
建站咨詢
