WCF:什么是ServiceHost的? [英] WCF: What is a ServiceHost?

查看:199
本文介绍了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:

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx

这篇关于WCF:什么是ServiceHost的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆