WCF面向服务应用程序系列之十二:托管(Hosting)-基础知识.doc_第1页
WCF面向服务应用程序系列之十二:托管(Hosting)-基础知识.doc_第2页
WCF面向服务应用程序系列之十二:托管(Hosting)-基础知识.doc_第3页
WCF面向服务应用程序系列之十二:托管(Hosting)-基础知识.doc_第4页
WCF面向服务应用程序系列之十二:托管(Hosting)-基础知识.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

WCF面向服务应用程序系列之十二:托管(Hosting)-基础知识 在前面的一些章节中,我们根据DEMO来演示WCF的相关特性,其中我们一直在用WCF服务端,然而WCF服务类不能凭空存在。每个WCF服务都必须进行托管(Hosting)在Windows进程中,该进程被称为宿主进程(Host Process)。 宿主进程与WCF服务的关系:单个宿主进程可以托管多个服务,而相同的服务类型也能够托管在多个宿主进程中。 WCF的托管的环境有很多种,下面介绍一些常用的托管环境:IIS托管:在IIS中托管服务。优势为宿主进程可以在客户端提交第一次请求的时候自动启动,还可以借助IIS管理宿主进程的生命周期。缺点为只能使用HTTP协议,如果是IIS5还要受端口限制,要求所有服务必须使用相同的端口号。Web站点的配置文件(web.config)必须列出需要公开为服务的类型,类型使用类型全称,如果服务类型来自于一个没有被引用的程序集,则还要包括程序集名,配置如下: . 自托管:Self-Hosting,由开发者提供和管理宿主进程的生命周期。自托管进程可以是控制台应用程序、Windows应用程序、Windows服务等,进程必须在客户端调用服务之前运行。自托管支持通信的协议包括:HTTP、TCP、IPC、MSMQ。 自托管宿主进程必须在运行时显示地注册服务类型,同时为客户端的调用打开宿主,因此才要求宿主进程必须在客户端调用到达之前运行。创建宿主进程的方法通常是在Main() 方法中调用ServiceHost类。ServiceHost类的定义如下:ICommunicationObject代码 / Summary: / Defines the contract for the basic state machine for all communication-oriented / objects in the system, including channels, the channel managers, factories, / listeners, and dispatchers, and service hosts. public interface ICommunicationObject / Summary: / Gets the current state of the communication-oriented object. / / Returns: / The value of the System.ServiceModel.CommunicationState of the object. CommunicationState State get; / Summary: / Occurs when the communication object completes its transition from the closing / state into the closed state. event EventHandler Closed; / / Summary: / Occurs when the communication object first enters the closing state. event EventHandler Closing; / / Summary: / Occurs when the communication object first enters the faulted state. event EventHandler Faulted; / / Summary: / Occurs when the communication object completes its transition from the opening / state into the opened state. event EventHandler Opened; / / Summary: / Occurs when the communication object first enters the opening state. event EventHandler Opening; / Summary: / Causes a communication object to transition immediately from its current / state into the closed state. void Abort(); / / Summary: / Begins an asynchronous operation to close a communication object. / / Parameters: / callback: / The System.AsyncCallback delegate that receives notification of the completion / of the asynchronous close operation. / / state: / An object, specified by the application, that contains state information / associated with the asynchronous close operation. / / Returns: / The System.IAsyncResult that references the asynchronous close operation. / / Exceptions: / System.ServiceModel.CommunicationObjectFaultedException: / System.ServiceModel.ICommunicationObject.BeginClose() was called on an object / in the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The default timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to close gracefully. IAsyncResult BeginClose(AsyncCallback callback, object state); / / Summary: / Begins an asynchronous operation to close a communication object with a specified / timeout. / / Parameters: / timeout: / The System.Timespan that specifies how long the send operation has to complete / before timing out. / / callback: / The System.AsyncCallback delegate that receives notification of the completion / of the asynchronous close operation. / / state: / An object, specified by the application, that contains state information / associated with the asynchronous close operation. / / Returns: / The System.IAsyncResult that references the asynchronous close operation. / / Exceptions: / System.ServiceModel.CommunicationObjectFaultedException: / System.ServiceModel.ICommunicationObject.BeginClose() was called on an object / in the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The specified timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to close gracefully. IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state); / / Summary: / Begins an asynchronous operation to open a communication object. / / Parameters: / callback: / The System.AsyncCallback delegate that receives notification of the completion / of the asynchronous open operation. / / state: / An object, specified by the application, that contains state information / associated with the asynchronous open operation. / / Returns: / The System.IAsyncResult that references the asynchronous open operation. / / Exceptions: / System.ServiceModel.CommunicationException: / The System.ServiceModel.ICommunicationObject was unable to be opened and / has entered the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The default open timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to enter the System.ServiceModel.CommunicationState.Opened state / and has entered the System.ServiceModel.CommunicationState.Faulted state. IAsyncResult BeginOpen(AsyncCallback callback, object state); / / Summary: / Begins an asynchronous operation to open a communication object within a / specified interval of time. / / Parameters: / timeout: / The System.Timespan that specifies how long the send operation has to complete / before timing out. / / callback: / The System.AsyncCallback delegate that receives notification of the completion / of the asynchronous open operation. / / state: / An object, specified by the application, that contains state information / associated with the asynchronous open operation. / / Returns: / The System.IAsyncResult that references the asynchronous open operation. / / Exceptions: / System.ServiceModel.CommunicationException: / The System.ServiceModel.ICommunicationObject was unable to be opened and / has entered the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The specified timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to enter the System.ServiceModel.CommunicationState.Opened state / and has entered the System.ServiceModel.CommunicationState.Faulted state. IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state); / / Summary: / Causes a communication object to transition from its current state into the / closed state. / / Exceptions: / System.ServiceModel.CommunicationObjectFaultedException: / System.ServiceModel.ICommunicationObject.Close() was called on an object / in the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The default close timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to close gracefully. void Close(); / / Summary: / Causes a communication object to transition from its current state into the / closed state. / / Parameters: / timeout: / The System.Timespan that specifies how long the send operation has to complete / before timing out. / / Exceptions: / System.ServiceModel.CommunicationObjectFaultedException: / System.ServiceModel.ICommunicationObject.Close() was called on an object / in the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The timeout elapsed before the System.ServiceModel.ICommunicationObject was / able to close gracefully. void Close(TimeSpan timeout); / / Summary: / Completes an asynchronous operation to close a communication object. / / Parameters: / result: / The System.IAsyncResult that is returned by a call to the System.ServiceModel.ICommunicationObject.BeginClose() / method. / / Exceptions: / System.ServiceModel.CommunicationObjectFaultedException: / System.ServiceModel.ICommunicationObject.BeginClose() was called on an object / in the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The timeout elapsed before the System.ServiceModel.ICommunicationObject was / able to close gracefully. void EndClose(IAsyncResult result); / / Summary: / Completes an asynchronous operation to open a communication object. / / Parameters: / result: / The System.IAsyncResult that is returned by a call to the System.ServiceModel.ICommunicationObject.BeginOpen() / method. / / Exceptions: / System.ServiceModel.CommunicationException: / The System.ServiceModel.ICommunicationObject was unable to be opened and / has entered the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The timeout elapsed before the System.ServiceModel.ICommunicationObject was / able to enter the System.ServiceModel.CommunicationState.Opened state and / has entered the System.ServiceModel.CommunicationState.Faulted state. void EndOpen(IAsyncResult result); / / Summary: / Causes a communication object to transition from the created state into the / opened state. / / Exceptions: / System.ServiceModel.CommunicationException: / The System.ServiceModel.ICommunicationObject was unable to be opened and / has entered the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The default open timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to enter the System.ServiceModel.CommunicationState.Opened state / and has entered the System.ServiceModel.CommunicationState.Faulted state. void Open(); / / Summary: / Causes a communication object to transition from the created state into the / opened state within a specified interval of time. / / Parameters: / timeout: / The System.Timespan that specifies how long the send operation has to complete / before timing out. / / Exceptions: / System.ServiceModel.CommunicationException: / The System.ServiceModel.ICommunicationObject was unable to be opened and / has entered the System.ServiceModel.CommunicationState.Faulted state. / / System.TimeoutException: / The specified timeout elapsed before the System.ServiceModel.ICommunicationObject / was able to enter the System.ServiceModel.CommunicationState.Opened state / and has entered the System.ServiceModel.CommunicationState.Faulted state. void Open(TimeSpan timeout); CommunicationObject 代码 / Summary: / Provides a common base implementation for the basic state machine common / to all communication-oriented objects in the system, includi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论