这篇文章主要讲解了“WCF自托管宿主是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“WCF自托管宿主是什么”吧!利用WCF提供的ServiceHost<T>提供的Open()
这篇文章主要讲解了“WCF自托管宿主是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“WCF自托管宿主是什么”吧!
利用WCF提供的ServiceHost<T>提供的Open()和Close()方法,可以便于开发者在控制台应用程序,windows应用程序乃至于asp.net应用程序中托管服务。不管自宿主的环境是何种应用程序,实质上托管服务的方式都是一致的。例如在控制台应用程序中:
using (ServiceHost host = new ServiceHost(typeof(DocumentsExplorerService))) { host.Open(); Console.WriteLine("The Service had been launched."); Console.Read(); }
ServiceHost实例是被创建在应用程序域中,因此我们必须保证宿主进程在调用服务期间不会被关闭,因此我们利用Console.Read() 来阻塞进程,以使得控制台应用程序能够一直运行,直到认为地关闭应用程序。如果是Windows应用程序,则可以将创建ServiceHost实例的代码放在主窗体的相关代码中,保证服务WCF自托管宿主不会被关闭。相应地,我们需要配置应用程序的app.config配置文件:
<configuration> <system.serviceModel> <services> <service name="BruceZhang.WCF.DocumentsExplorerServiceImplementation.DocumentsExplorerService" behaviorConfiguration="DocumentExplorerServiceBehavior"> <host> <baseAddresses> <add baseAddress="Http://localhost:8008/DocumentExplorerService"/> </baseAddresses> </host> <endpoint address="" binding="basicHttpBinding" bindinGConfiguration="DocumentExplorerServiceBinding" contract="BruceZhang.WCF.DocumentsExplorerServiceContract.IDocumentsExplorerService"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <bindings> <basicHttpBinding> <binding name="DocumentExplorerServiceBinding" sendTimeout="00:10:00" transferMode="Streamed" messageEncoding="Text" textEncoding="utf-8" maxReceivedMessageSize="9223372036854775807"> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="DocumentExplorerServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
注意,配置文件中的服务名必须包含服务契约以及服务类的命名空间。此外,在配置文件中我通过<baseAddresses>标签为服务添加了基地址,因此在endpoint中,address为""。
感谢各位的阅读,以上就是“WCF自托管宿主是什么”的内容了,经过本文的学习后,相信大家对WCF自托管宿主是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!
--结束END--
本文标题: WCF自托管宿主是什么
本文链接: https://www.lsjlt.com/news/292671.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模
0