自托管 WCF ServiceHost/WebServiceHost 并发/性能设计选项 (.NET 3.5)

发布于 2024-09-01 12:27:21 字数 845 浏览 14 评论 0原文

因此,我将通过自托管(在 WindowsService 中)WebServiceHost 提供一些功能(不确定如何使用 ServiceHost 处理 HTTP GET/POST),其中之一可能会被大量调用。此函数还将依赖于应用程序域中的连接(由 WindowsService 托管,因此它可以在多个请求下保持活动状态)。

我有以下问题,非常感谢任何输入/想法/评论:

  • 并发访问 - WebServiceHost 如何处理一堆并发请求。它们是按顺序排队和处理还是自动创建合约的新实例?
  • WebServiceHost-> WindowsService 通信 - 我需要从 WebServiceHost 到托管 WindowsService 进行某种形式的通信,以实现诸如请求新会话(如果会话不存在)之类的操作。也许实现一个类,用 WindowsService 订阅的事件扩展 WebServiceHost...(除非有另一种方法可以在发出请求时在 WindowsService 中引发事件...)
  • 多个 WebServiceHost 或契约< /b> - 在不同线程中运行多个 WebServiceHost 实例(也许每个端点一个?)是否会带来真正的性能提升? - 更好地理解第一点可能会有所帮助。
  • WSDL - 我不确定为什么(可能只需要阅读更多内容),但我不确定如何让 WebServiceHost 基本端点以描述可用合同的 WDSL 文档进行响应。不是必需的,因为所有操作都将通过 GET 请求完成,这不太可能改变,但如果有的话那就太好了......

目前就这样;)我已经阅读了很多关于 WCF 的内容,并希望我能很久以前就开始接触它了,但肯定还在学习中。

So I'll be providing a few functions via a self hosted (in a WindowsService) WebServiceHost (not sure how to process HTTP GET/POST with ServiceHost), one of which may be called a large amount of the time. This function will also rely on a connection in the appdomain (hosted by the WindowsService so it can stay alive over multiple requests).

I have the following concerns and would be oh so thankful for any input/thoughts/comments:

  • Concurrent access - how does the WebServiceHost handle a bunch of concurrent requests. Are they queued and processes sequentially or are new instances of the contracts automagically created?
  • WebServiceHost -> WindowsService communication - I need some form of communication from the WebServiceHost to the hosting WindowsService for things like requesting a new session if one does not exist. Perhaps implementing a class which extends the WebServiceHost with events which the WindowsService subscribes to... (unless there is another way I can set off an event in the WindowsService when a request is made...)
  • Multiple WebServiceHosts or Contracts - Would it give any real performance gain to be running multiple WebServiceHost instances in different threads (one per endpoint perhaps?) - A better understanding of the first point would probably help here.
  • WSDL - I'm not sure why (probably just need to do more reading), but I'm not sure how to get the WebServiceHost base endpoint to respond with a WDSL document describing the available contract. Not required as all the operations will be done via GET requests which will not likely change, but it would be nice to have...

That's about it for the moment ;) I've been reading a lot on WCF and wish I'd gotten into it long ago, but definitely still learning.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖不如嘢 2024-09-08 12:27:21

并发访问 - 您可以使用 ServiceBehaviorAttribute 进行设置。有多种选择——您可以让 WCF 为每个传入请求创建服务类的新实例,或者您可以让单个实例处理所有请求。此外,您还可以告诉 WCF 是串行还是并发地向您传递请求。

WebServiceHost-> Windows服务通信。我想到了两种方法:WCF 支持一种称为“众所周知的实例”的模式,您可以将服务的实例传递给 ServiceHost 构造函数,而不是传递 Type 并让 WCF 为您实例化它。使用此模式,您可以使用对托管代码的引用来预配置服务实例(或者您可以使用事件)。如果您想保留实例灵活性,另一种方法是在托管代码中使用 WCF 服务可以回调的静态方法。

多个 WebServiceHosts 或 Contracts - 拥有多个 ServiceHost 实例实际上没有任何优势。另请参阅此线程: 什么是对多个服务主机的好处?一个 ServiceHost 是否支持一个端点上的多个同时连接?

WSDL - 虽然您可以通过打开元数据发布来启用 WSDL (http://msdn .microsoft.com/en-us/library/ms788760.aspx),WSDL 支持适用于基于 SOAP 的服务,而不是纯粹的 HTTP GET/POST。为您的服务自动生成的 WSDL 可能不是很有用。

Concurrent access - this is something you can set using ServiceBehaviorAttribute. there are a number of options -- you can have WCF create a new instance of your service class for each incoming request, or you can have a single instance handle all requests. Additionally you can tell WCF whether to pass you the requests serially or concurrently.

WebServiceHost -> WindowsService communication. Two approaches spring to mind: WCF supports a mode called "well known instance" where you pass an instance of your service to the ServiceHost constructor instead of passing a Type and letting WCF instantiate it for you. With this mode you can preconfigure your service instance with a reference back to your hosting code (alternatively you could use events). An alternative if you want to preserve instancing flexibility would be to have a static method in your hosting code that the WCF service could call back into.

Multiple WebServiceHosts or Contracts - really no advantage to having more than one ServiceHost instance. see also this SO thread: What are the benefits for several servicehosts? Does one ServiceHost support several simultaneous connections on one endpoint?.

WSDL - While you can enable WSDL by turning on metadata publishing (http://msdn.microsoft.com/en-us/library/ms788760.aspx), WSDL support is intended for SOAP-based services, not pure HTTP GET/POST. The WSDL that gets auto-generated for your service will likely not be very useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文