偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

WCF服務宿主程序正確實現方法解析

開發(fā) 開發(fā)工具
我們今天將會通過一段完整的代碼為大家詳細介紹一下WCF服務宿主程序的相關實現技巧,相信通過對本文的解讀,能夠充分掌握這一技巧。

WCF開發(fā)工具是微軟公司研發(fā)的一種功能強大的開發(fā)插件,是一個.NET Framework 3.5的重要組成部分。我們今天將會通過這篇文章中介紹的內容充分的了解到有關WCF服務宿主程序的實現方法。#t#

(1)在類文件中,添加using語句來導入下面的名字空間:

·System.ServiceModel

·System.Configuration

·DerivativesCalculatorService

(2)代碼看起來應該如下所示:

 

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Configuration;  
  6. using System.ServiceModel;  
  7. using DerivativesCalculatorService;  
  8. namespace Host  
  9. {  
  10. class Program  
  11. {  
  12. static void Main(string[] args)  
  13. {  
  14. }  
  15. }  

 

(3)在Main方法中添加下面的代碼:

 

 

  1. static void Main(string[] args)  
  2. {  
  3. Type serviceType = typeof(Calculator);  
  4. using (ServiceHost host = new ServiceHost(serviceType))  
  5. {  
  6. }  

 

***行WCF服務宿主程序的代碼得到一個類型引用,這個類型就是具體實現WCF服務的那個類,也是我們將要在宿主程序中運行的類。

using語句用來對ServiceHost實例進行初始化,在作用域結束時ServiceHost的Dispose()會被自動調用。

(4)在using語句內部,我們先啟動ServiceHost,然后通過等待用戶輸入的方式來阻止應用程序退出。

(5)下面是完整的WCF服務宿主程序代碼,新增的代碼加亮顯示。

 

 

  1. namespace Host  
  2. {  
  3. class Program  
  4. {  
  5. static void Main(string[] args)  
  6. {  
  7. Type serviceType = typeof(Calculator);  
  8. using (ServiceHost host = new ServiceHost(serviceType))  
  9. {  
  10. host.Open();  
  11. Console.WriteLine("The calculator service is available.");  
  12. Console.ReadKey();  
  13. }  
  14. }  
  15. }  

 

(6)選擇File | Save All菜單項。

(7)在進入下一個任務之前請確保解決方案能夠編譯通過(按CTRL+Shift+B快捷鍵)。

以上就是我們?yōu)榇蠹医榻B的有關WCF服務宿主程序的相關內容。

責任編輯:曹凱 來源: CSDN
相關推薦

2010-02-25 16:52:12

引用WCF服務

2010-02-26 11:22:16

LitwareHR使用

2010-02-24 10:41:28

WCF服務保護

2010-02-25 13:48:23

WCF動態(tài)創(chuàng)建代碼

2010-02-25 09:13:34

WCF異步調用

2010-02-25 10:10:29

WCF使用Header

2010-02-26 10:30:03

ASP.NET Aja

2010-02-24 10:07:48

WCF跨越邊界

2010-03-03 17:10:57

Python操作Sql

2010-02-24 13:48:44

MSMQ使用WCF

2009-12-21 10:09:26

WCF創(chuàng)建客戶端服務對

2010-02-26 16:05:14

寄宿WCF服務

2010-03-04 11:12:02

Python AOP

2010-03-05 16:51:01

Python程序轉為E

2010-02-22 14:28:35

WCF實現loadin

2010-01-06 14:22:29

.NET Framew

2010-02-23 10:51:32

WCF Address

2010-03-01 17:44:39

Silverlight

2010-01-22 13:08:50

VB.NET創(chuàng)建數組

2009-12-29 18:09:00

Silverlight
點贊
收藏

51CTO技術棧公眾號