简体   繁体   English

WCF自我托管,通过控制台应用程序托管

[英]WCF self hosting, hosting via Console app

I have seen examples, sample codes etc for self hosting WCF services within a console app, windows service etc. 我在控制台应用程序,Windows服务等中看到了用于自托管WCF服务的示例,示例代码等。

My question is, how will this work in production? 我的问题是,这在生产中将如何工作? Will it be efficient? 会有效吗? Will it scale? 会缩放吗?

I m not sure, how it will work, so other question is, will that be single threaded? 我不确定它如何工作,所以另一个问题是单线程吗? multi threaded? 多线程的? do i need to manage the multi threading? 我需要管理多线程吗? appdomains? 应用程序域?

I prefer hosting with command line, windows service for application related reasons. 由于与应用程序相关的原因,我更喜欢使用命令行,Windows服务进行托管。

My question is, 我的问题是
Will it be efficient? 会有效吗? Will it scale? 会缩放吗?

Yes and yes. 是的,是的。 But for really large scale apps you should still consider IIS (+WAS). 但是对于真正大规模的应用程序,您仍应考虑使用IIS(+ WAS)。

so other question is, will that be single threaded? 所以另一个问题是,那将是单线程的吗? multi threaded? 多线程的?

That is determined by the configuration. 这取决于配置。

Will it be efficient? 会有效吗?

It depends on the service implementation, on the maximum number of requests it is able to manage within a specific time-frame. 它取决于服务的实现,取决于它在特定时间范围内可以管理的最大请求数。 Efficiency is a relative measure: let's assume your service is able to process 20 messages/sec, if your requirement is to be able to process 10 messages/sec, then your service is efficient. 效率是一个相对的度量:假设您的服务能够每秒处理20条消息,如果您的要求是每秒能够处理10条消息,那么您的服务就是有效的。 But if the requirement is 30, then it is not. 但是,如果要求是30,则不是。

Will it scale? 会缩放吗?

Once again, it is not related to hosting. 再一次,它与托管无关。 Are your services stateless? 您的服务是无状态的吗? if not then, they probably won't scale much since load balancing is not possible. 如果不是这样的话,由于不可能进行负载平衡,它们可能不会扩展太多。

Will it be manageable ? 可以管理吗?

Probably not: - you need to have a user logged on the server to run the app - it does not auto-start with the server - it cannot auto-restart on failure - it does not create instances of the service pro-actively - it does not provide (without custom code) a way to check the service health 可能不是:-您需要在服务器上登录用户才能运行该应用程序-它不会随服务器自动启动-它无法在失败时自动重新启动-它不会主动创建服务实例-它没有提供(没有自定义代码)检查服务运行状况的方法

Single instance ? 单实例? Multiple threads ? 多线程?

If your service does not maintain state between calls per client, then configure it as "one instance per call and no multithreading" -> No concurrency, high throughput 如果您的服务不能在每个客户端调用之间保持状态,则将其配置为“每个调用一个实例且没有多线程”->无并发,高吞吐量

If your service does maintain state, then configure it as "one instance per session and multithreading" to allow a client to perform concurrent calls. 如果您的服务确实保持状态,则将其配置为“每个会话和多线程一个实例”,以允许客户端执行并发调用。 Be careful about concurrency issues and protect your resources. 注意并发问题并保护您的资源。

If your service does not maintain state per client but keeps some global data stored for all calls, consider the "single instance per service and multithreading". 如果您的服务不维护每个客户端的状态,而是为所有调用保留一些全局数据,请考虑“每个服务和多线程单个实例”。 Keep in mind the possible concurrency issues. 请记住可能存在的并发问题。 In that you might as well use "one instance per call" and keep the global storage out the service. 这样,您最好使用“每个调用一个实例”并将全局存储保留在服务之外。

A Windows service hosting a WCF endpoint is fine for small services that aren't going to be hit often; 承载WCF端点的Windows服务非常适合小型服务,这些服务不会经常受到攻击。 you don't have to mess with IIS (which can be a REAL pain IMO). 您不必弄乱IIS(这可能是IMO的痛苦)。 However, there will only be one listener listening, so it's not recommended for a service that is likely to be hit from several places at once (use IIS for that; it sets up an app pool that can handle many simultaneous requests). 但是,只有一个侦听器在侦听,因此不建议将可能同时从多个位置访问的服务(为此使用IIS;它会设置一个可以处理多个同时请求的应用程序池)。 This model is good for one-on-one interop between two machines; 该模型适用于两台机器之间的一对一互操作。 you might set up the service host on a "set and forget" box living out in a warehouse somewhere, and call it to perform simple but custom tasks like rebooting, log dumps, etc. 您可以在生活在某个地方的仓库中的“设置并忘记”框中设置服务主机,然后调用它执行简单但自定义的任务,例如重新启动,日志转储等。

Avoid having any user app (console or otherwise) host a service endpoint, except for initial proof-of-concept testing. 除初始概念验证测试外,请避免让任何用户应用程序(控制台或其他方式)托管服务端点。 In addition to the single-listener drawback, a user app MUST be run in the context of a logged-in user (not the service users, which are "logged in" as part of Windows startup), and must have custom "keepalive" monitoring; 除了单听程序的缺点之外,用户应用程序必须在登录用户(不是服务用户,在Windows启动过程中被“登录”)的上下文中运行,并且必须具有自定义的“ keepalive”监测; with a service, Windows can be told to simply restart it if it crashes, while it doesn't give a toss about a user app crashing other than to prevent that program taking down the whole OS (and to ask the user if they want to report the crash). 使用服务时,可以告诉Windows在崩溃时只需重新启动它,而不会阻止用户程序崩溃,而只是防止该程序破坏整个操作系统(并询问用户是否要这样做)。报告崩溃)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM