WCF服務(wù)元數(shù)據(jù)交換編程怎么實現(xiàn)

這篇文章主要講解了“WCF服務(wù)元數(shù)據(jù)交換編程怎么實現(xiàn)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“WCF服務(wù)元數(shù)據(jù)交換編程怎么實現(xiàn)”吧!

你所需要的網(wǎng)站建設(shè)服務(wù),我們均能行業(yè)靠前的水平為你提供.標(biāo)準(zhǔn)是產(chǎn)品質(zhì)量的保證,主要從事成都網(wǎng)站制作、網(wǎng)站設(shè)計、外貿(mào)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站建設(shè)、成都手機(jī)網(wǎng)站制作、網(wǎng)頁設(shè)計、成都品牌網(wǎng)站建設(shè)、網(wǎng)頁制作、做網(wǎng)站、建網(wǎng)站。創(chuàng)新互聯(lián)擁有實力堅強的技術(shù)研發(fā)團(tuán)隊及素養(yǎng)的視覺設(shè)計專才。

前者配置簡單、快捷,后者相對復(fù)雜。但是編程方式允許代碼運行時控制或者設(shè)置元數(shù)據(jù)交換的信息。因而更加靈活。下面我們就來看看如何通過代碼實現(xiàn)剛才的服務(wù)原數(shù)據(jù)交換的配置。

WCF服務(wù)元數(shù)據(jù)交換HTTP-GET編程實現(xiàn):

必須添加對命名空間的引用, using System.ServiceModel.Description;我們對服務(wù)元數(shù)據(jù)操作的類和接口信息定義在此命名空間里,具體的實現(xiàn)HTTP-GET的代碼如下:

ServiceMetadataBehavior metadataBehavior;  //定義服務(wù)行為變量,  metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();  //獲取宿主的行為列表  if (metadataBehavior == null)  //如果沒有服務(wù)原數(shù)據(jù)交換的行為,實例化添加服務(wù)原數(shù)據(jù)交換行為  {  metadataBehavior = new ServiceMetadataBehavior();  Uri httpAddress = new Uri("http://localhost:8001/");  metadataBehavior.HttpGetUrl =httpAddress;  metadataBehavior.HttpGetEnabled = true;//設(shè)置HTTP方式  host.Description.Behaviors.Add(metadataBehavior);  }

首先是獲得服務(wù)行為的列表信息,如果沒有設(shè)置,我們就進(jìn)行實例化服務(wù)原數(shù)據(jù)交換行為,并設(shè)置http方式可用。 host.Description.Behaviors.Add(metadataBehavior);添加宿主服務(wù)的行為。

WCF服務(wù)元數(shù)據(jù)交換WS-*編程實現(xiàn):

這里分別實現(xiàn)了HTTP、TCP、IPC三種方式的的元數(shù)據(jù)交換的代碼。和http-get方式略有不同,我們需要實例化自己綁定元素和綁定,***作為參數(shù)傳遞給host宿主實例。具體實現(xiàn)代碼如下:

//2編程方式實現(xiàn)ws*原數(shù)據(jù)交換  //生命三個綁定節(jié)點類  BindingElement tcpBindingElement = new TcpTransportBindingElement();  BindingElement httpBindingElement = new HttpsTransportBindingElement();  BindingElement pipeBindingElement = new NamedPipeTransportBindingElement();  //實例化通用綁定類的實例  Binding tcpBinding = new CustomBinding(tcpBindingElement);  Binding httpBinding = new CustomBinding(httpBindingElement);  Binding pipeBinding = new CustomBinding(pipeBindingElement);  //  Uri tcpBaseAddress = new Uri("net.tcp://localhost:9001/");  Uri httpBaseAddress = new Uri("http://localhost:9002/");  Uri pipeBaseAddress = new Uri("net.pipe://localhost/");  host.AddServiceEndpoint(typeof(WCFService.IWCFService), new NetTcpBinding(), tcpBaseAddress);  host.AddServiceEndpoint(typeof(WCFService.IWCFService), new WSHttpBinding(), httpBaseAddress);  host.AddServiceEndpoint(typeof(WCFService.IWCFService), new NetNamedPipeBinding(), pipeBaseAddress);   //ServiceMetadataBehavior metadataBehavior;//定義服務(wù)行為變量,  metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();  //獲取宿主的行為列表  if (metadataBehavior == null)//如果沒有服務(wù)原數(shù)據(jù)交換的行為,實例化添加服務(wù)原數(shù)據(jù)交換行為  {  metadataBehavior = new ServiceMetadataBehavior();   host.Description.Behaviors.Add(metadataBehavior);  }  //如果沒有可用的mex節(jié)點,可以使用一下代碼判斷,添加mex節(jié)點   host.AddServiceEndpoint(typeof(IMetadataExchange), tcpBinding, "mex");  host.AddServiceEndpoint(typeof(IMetadataExchange), httpBinding, "mex");  host.AddServiceEndpoint(typeof(IMetadataExchange), pipeBinding, "mex");

感謝各位的閱讀,以上就是“WCF服務(wù)元數(shù)據(jù)交換編程怎么實現(xiàn)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對WCF服務(wù)元數(shù)據(jù)交換編程怎么實現(xiàn)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

名稱欄目:WCF服務(wù)元數(shù)據(jù)交換編程怎么實現(xiàn)
轉(zhuǎn)載注明:http://muchs.cn/article18/jcggdp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、移動網(wǎng)站建設(shè)網(wǎng)站營銷、網(wǎng)站排名網(wǎng)站內(nèi)鏈、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)