WCF:什么是ServiceHost的?

编程入门 行业动态 更新时间:2024-10-10 19:22:32
本文介绍了WCF:什么是ServiceHost的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

由于我正在学习使用WCF服务,我经常遇到在互联网上教程有提到使用使用WCF服务时,的ServiceHost 。

As I'm currently learning to use WCF Services, I am constantly encountering tutorials on the internet which mention using a ServiceHost when using a WCF Service.

到底这是什么的ServiceHost ?

What exactly is this ServiceHost ?


在我当前的项目我使用WCF服务和具有我的应用程序引用它,每当我想消费从我的应用我只是实例的 ServiceClient 像这样的:

In my current project I am using a WCF Service and having a reference to it from my app and whenever I want to consume it from my app I just instantiate its ServiceClient like such:

new MusicRepo_DBAccess_ServiceClient(new InstanceContext(instanceContext), customBinding, endpointAddress);

,然后访问我的网站的方法( OperationContract的 S)从该实例(显然消耗方法之前打开它,并与打开后关闭它和关闭)

And then access my web methods (OperationContracts) from that instance (obviously opening it before consuming the method and closing it afterwards with Open and Close)

我的WCF服务主机我的IIS,我只是访问 .SVC 从我的应用程序实例化 ServiceClient 。

My WCF service is host in my IIS and I just access the .svc from my app to instantiate the ServiceClient.

那么,为什么和在使用的ServiceHost ?

So why and where is ServiceHost used?

推荐答案

一个ServiceHost的基本上为您提供您需要托管在非IIS的WCF服务,或者在设置应有尽有。为ServiceHost的一个共同的地方将是一个控制台应用程序或Windows服务。见从MSDN的示例代码如何设置在一个控制台应用程序一个ServiceHost的:

A ServiceHost basically provides you everything you need to host a WCF service in a non-IIS or WAS setting. A common place for a ServiceHost would be in a console app or Windows service. See the example code from MSDN for how to setup a ServiceHost in a console app:

的msdn.microsoft/en-us/library/system.servicemodel.servicehost.aspx

更多推荐

WCF:什么是ServiceHost的?

本文发布于:2023-11-13 04:42:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583458.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WCF   ServiceHost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!