日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
WCF行為控制代碼示例應(yīng)用解讀

WCF開發(fā)工具中有很多比較重要的應(yīng)用技術(shù)及供功能特點(diǎn)需要我們熟練應(yīng)用。在這里我們將會(huì)為大家詳細(xì)介紹一下有關(guān)WCF行為控制的相關(guān)內(nèi)容。希望大家可以從這里介紹的內(nèi)容中獲得相關(guān)幫助。#t#

在嘉定等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需求定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,全網(wǎng)整合營(yíng)銷推廣,成都外貿(mào)網(wǎng)站制作,嘉定網(wǎng)站建設(shè)費(fèi)用合理。

在完成服務(wù)契約設(shè)計(jì)和服務(wù)實(shí)現(xiàn)后,我們可以設(shè)置該服務(wù)的運(yùn)行期行為(Behavior)。這些WCF行為控制包括 Service Behaviors、Endpoint Behaviors、Contract Behaviors、Operation Behaviors。

有關(guān)所有行為的說(shuō)明,可以查看 ms-help://MS.MSSDK.1033/MS.NETFX30SDK.1033/WCF_con/html/5c5450ea-6af1-4b75-a267-613d0ac54707.htm。

以下就常用的行為使用,做些演示。

ServiceBehaviorAttribute & OperationBehaviorAttribute

這是兩個(gè)最常用的WCF行為控制特性,可用于控制:

服務(wù)對(duì)象生命周期。

并發(fā)管理。

異步通訊。

配置文件參數(shù)。

事務(wù)。

元數(shù)據(jù)轉(zhuǎn)換。

會(huì)話(Session)周期。

等等...

 
 
 
  1. [ServiceContract]
  2. public interface ICalculate
  3. {
  4. [OperationContract]
  5. int Add(int a, int b);
  6. }
  7. [ServiceBehavior(InstanceContextModeInstanceContextMode=
    InstanceContextMode.PerCall)]
  8. public class CalculateService : ICalculate
  9. {
  10. public int Add(int a, int b)
  11. {
  12. Console.WriteLine(this.GetHashCode());
  13. return a + b;
  14. }
  15. }
  16. public class WcfTest
  17. {
  18. public static void Test()
  19. {
  20. AppDomain.CreateDomain("Server").DoCallBack(delegate
  21. {
  22. ServiceHost host = new ServiceHost(typeof(CalculateService));
  23. host.AddServiceEndpoint(typeof(ICalculate), new WSHttpBinding(), 
    "http://localhost:8080/calc");
  24. host.Open();
  25. });
  26. ChannelFactory factory = new ChannelFactory
    (new WSHttpBinding(), 
  27. "http://localhost:8080/calc");
  28. ICalculate o = factory.CreateChannel();
  29. Console.WriteLine(o.Add(1, 2));
  30. Console.WriteLine(o.Add(1, 2));
  31. factory.Close();
  32. }
  33. }

輸出:

 
 
 
  1. 30136159
  2. 3
  3. 41153804
  4. 3
  5. ServiceMetadataBehavior

用于開啟元數(shù)據(jù)獲取功能。只有使用該WCF行為控制,客戶端才能通過(guò) Svcutil.exe 或其他工具獲取服務(wù)信息,進(jìn)而生成客戶端代理文件。

 
 
 
  1. ServiceHost host = new ServiceHost(typeof(CalculateService));
  2. host.AddServiceEndpoint(typeof(ICalculate), 
    new BasicHttpBinding(), "http://localhost:8080/calc");
  3. ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
  4. behavior.HttpGetEnabled = true;
  5. behavior.HttpGetUrl = new Uri("http://localhost:8080/calc");
  6. host.Description.Behaviors.Add(behavior);
  7. host.Open();
  8. ServiceDebugBehavior

開啟調(diào)試功能,如將服務(wù)器端的異常信息直接傳送給客戶端。

 
 
 
  1. ServiceHost host = new ServiceHost(typeof(CalculateService));
  2. host.AddServiceEndpoint(typeof(ICalculate), 
    new WSHttpBinding(), "http://localhost:8080/calc");
  3. host.Description.Behaviors.Find()
    .IncludeExceptionDetailInFaults = true;
  4. host.Open();

以上就是對(duì)WCF行為控制的相關(guān)介紹。


本文標(biāo)題:WCF行為控制代碼示例應(yīng)用解讀
網(wǎng)站路徑:http://www.dlmjj.cn/article/cojcsgj.html