windows 每个 WCF 服务的新 ServiceHost?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1708343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:25:15  来源:igfitidea点击:

new ServiceHost for every WCF service?

c#.netwindowswcfservice

提问by user137348

First,Im running a windows service that should contain a lot of funcionality.There will be a business layer and the results comming from this business layer will be sent over WCF to the presentation layer.

首先,我正在运行一个应该包含很多功能的 Windows 服务。会有一个业务层,来自这个业务层的结果将通过 WCF 发送到表示层。

I dont know how to structe all this functionality.

我不知道如何构建所有这些功能。

So my questions are :

所以我的问题是:

1. Should I create somekind of a Facade pattern class that will cover all the service classes and put this one Facade Class to one ServiceHost. Or just create a ServiceHost instance for every service class?? Like this

1. 我是否应该创建某种 Facade 模式类来覆盖所有服务类并将这个 Facade 类放到一个 ServiceHost 中。或者只是为每个服务类创建一个 ServiceHost 实例?像这样

host1 = new ServiceHost(typeof(MyService1));
host2 = new ServiceHost(typeof(MyService2));

2.How granular should be my service classes? Per enitity or per aggregate root or per some functionality block ?

2.我的服务类应该多细化?每个实体或每个聚合根或每个功能块?

This communication will run over net.pipe.

此通信将通过 net.pipe 运行。

回答by grenade

There's an example of running multiple service hosts under a single windows service here: http://thegrenade.blogspot.com/2009/08/hosting-multiple-wcf-services-under.html

这里有一个在单个 Windows 服务下运行多个服务主机的示例:http: //thegrenade.blogspot.com/2009/08/hosting-multiple-wcf-services-under.html

And a related question here: Can you host multiple WCF processes in a single windows service?

还有一个相关的问题:您能否在单个 Windows 服务中托管多个 WCF 进程?

回答by Matt Davis

Let your interfaces be your guide. Define the interfaces you plan to expose through WCF. This will define how many service classes you need, and consequently, how many ServiceHost instances you need.

让您的界面成为您的向导。定义您计划通过 WCF 公开的接口。这将定义您需要多少个服务类,因此,您需要多少个 ServiceHost 实例。

回答by marc_s

One ServiceHost can only host a single service (implementation) class - that's a given, you can't change that.

一个 ServiceHost 只能承载一个服务(实现)类 - 这是给定的,您无法更改。

But a service (implementation) class can implement any number of service contracts (interfaces).

但是一个服务(实现)类可以实现任意数量的服务契约(接口)。

However, living up to the separation of concerns principle, I don't see a lot of compelling reasons to have a humongous "SuperDuperServiceClass" which implements a boat load of service contracts - I like to keep things that have nothing to do with one another separate - makes it easier to manage it in the long run.

然而,按照关注点分离原则,我没有看到很多令人信服的理由来拥有一个巨大的“SuperDuperServiceClass”来实现大量的服务合同——我喜欢保留彼此无关的东西分开 - 从长远来看更容易管理它。

What's your reasoning against having a single service host for a single service?

您反对为单个服务使用单个服务主机的理由是什么?