自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WCF服務(wù)宿主程序正確實(shí)現(xiàn)方法解析

開(kāi)發(fā) 開(kāi)發(fā)工具
我們今天將會(huì)通過(guò)一段完整的代碼為大家詳細(xì)介紹一下WCF服務(wù)宿主程序的相關(guān)實(shí)現(xiàn)技巧,相信通過(guò)對(duì)本文的解讀,能夠充分掌握這一技巧。

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

(1)在類(lèi)文件中,添加using語(yǔ)句來(lái)導(dǎo)入下面的名字空間:

·System.ServiceModel

·System.Configuration

·DerivativesCalculatorService

(2)代碼看起來(lái)應(yīng)該如下所示:

 

 

  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服務(wù)宿主程序的代碼得到一個(gè)類(lèi)型引用,這個(gè)類(lèi)型就是具體實(shí)現(xiàn)WCF服務(wù)的那個(gè)類(lèi),也是我們將要在宿主程序中運(yùn)行的類(lèi)。

using語(yǔ)句用來(lái)對(duì)ServiceHost實(shí)例進(jìn)行初始化,在作用域結(jié)束時(shí)ServiceHost的Dispose()會(huì)被自動(dòng)調(diào)用。

(4)在using語(yǔ)句內(nèi)部,我們先啟動(dòng)ServiceHost,然后通過(guò)等待用戶(hù)輸入的方式來(lái)阻止應(yīng)用程序退出。

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

 

 

  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菜單項(xiàng)。

(7)在進(jìn)入下一個(gè)任務(wù)之前請(qǐng)確保解決方案能夠編譯通過(guò)(按CTRL+Shift+B快捷鍵)。

以上就是我們?yōu)榇蠹医榻B的有關(guān)WCF服務(wù)宿主程序的相關(guān)內(nèi)容。

責(zé)任編輯:曹凱 來(lái)源: CSDN
相關(guān)推薦

2010-02-25 16:52:12

引用WCF服務(wù)

2010-02-26 11:22:16

LitwareHR使用

2010-02-24 10:41:28

WCF服務(wù)保護(hù)

2010-02-25 13:48:23

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

2010-02-25 09:13:34

WCF異步調(diào)用

2010-02-25 10:10:29

WCF使用Header

2010-02-24 10:07:48

WCF跨越邊界

2010-02-26 10:30:03

ASP.NET Aja

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)建客戶(hù)端服務(wù)對(duì)

2010-03-05 16:51:01

Python程序轉(zhuǎn)為E

2010-02-26 16:05:14

寄宿WCF服務(wù)

2010-03-04 11:12:02

Python AOP

2010-02-22 14:28:35

WCF實(shí)現(xiàn)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)建數(shù)組

2010-01-14 17:52:54

VB.NET顯示系統(tǒng)信
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)