日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
關(guān)于WCF服務(wù)元數(shù)據(jù)交換編程揭密

WCF還是比較常用的,于是我研究了一下WCF服務(wù)元數(shù)據(jù)交換,在這里拿出來和大家分享一下,希望對大家有用。前者配置簡單、快捷,后者相對復(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的代碼如下:

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

#T#首先是獲得服務(wù)行為的列表信息,如果沒有設(shè)置,我們就進行實例化服務(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)代碼如下:

 
 
  1. //2編程方式實現(xiàn)ws*原數(shù)據(jù)交換  
  2. //生命三個綁定節(jié)點類  
  3. BindingElement tcpBindingElement = new TcpTransportBindingElement();  
  4. BindingElement httpBindingElement = new HttpsTransportBindingElement();  
  5. BindingElement pipeBindingElement = new NamedPipeTransportBindingElement();  
  6. //實例化通用綁定類的實例  
  7. Binding tcpBinding = new CustomBinding(tcpBindingElement);  
  8. Binding httpBinding = new CustomBinding(httpBindingElement);  
  9. Binding pipeBinding = new CustomBinding(pipeBindingElement);  
  10. //  
  11. Uri tcpBaseAddress = new Uri("net.tcp://localhost:9001/");  
  12. Uri httpBaseAddress = new Uri("http://localhost:9002/");  
  13. Uri pipeBaseAddress = new Uri("net.pipe://localhost/");  
  14. host.AddServiceEndpoint(typeof(WCFService.IWCFService), new NetTcpBinding(), tcpBaseAddress);  
  15. host.AddServiceEndpoint(typeof(WCFService.IWCFService), new WSHttpBinding(), httpBaseAddress);  
  16. host.AddServiceEndpoint(typeof(WCFService.IWCFService), new NetNamedPipeBinding(), pipeBaseAddress);  
  17.  
  18. //ServiceMetadataBehavior metadataBehavior;//定義服務(wù)行為變量,  
  19. metadataBehavior = host.Description.Behaviors.Find();  
  20. //獲取宿主的行為列表  
  21. if (metadataBehavior == null)//如果沒有服務(wù)原數(shù)據(jù)交換的行為,實例化添加服務(wù)原數(shù)據(jù)交換行為  
  22. {  
  23. metadataBehavior = new ServiceMetadataBehavior();  
  24.  
  25. host.Description.Behaviors.Add(metadataBehavior);  
  26. }  
  27. //如果沒有可用的mex節(jié)點,可以使用一下代碼判斷,添加mex節(jié)點  
  28.  
  29. host.AddServiceEndpoint(typeof(IMetadataExchange), tcpBinding, "mex");  
  30. host.AddServiceEndpoint(typeof(IMetadataExchange), httpBinding, "mex");  
  31. host.AddServiceEndpoint(typeof(IMetadataExchange), pipeBinding, "mex");  

本文題目:關(guān)于WCF服務(wù)元數(shù)據(jù)交換編程揭密
文章分享:http://www.5511xx.com/article/cdcgogc.html