我应承载在IIS中我的WCF服务? [英] Should I host my WCF service in IIS?

查看:169
本文介绍了我应承载在IIS中我的WCF服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我设计的WCF服务。我没有经验与WCF,我试图来决定是否应该在IIS中承载,或自定义Windows服务..或者一些其他的选择吗?

需要考虑的事项:

  • 它需要从启动数据库加载数据。
  • 它需要保持跨请求这个数据,而不是每次都加载它。
  • 它需要同时处理多个请求。
  • 在它需要的配置尽可能有关终点。
  • 将被调用本机DLL颇多。

我怀疑它托管在IIS中会简化某些东西,但我不知道它会在这种情况下是一个好主意。

什么是我的选择,和他们有什么利弊?

解决方案

您需要主要看三个选项:

1)托管在IIS6(在Windows Server 2003/2003 R2):在这种情况下,你只能承载HTTP协议 - 仅此而已。这本身就是一个相当的限制,不能使用如netTcp为Intranet方案。

2)托管在IIS7 / WAS(Vista中,服务器2008年):这给你支持的协议方面更加选项,并且主机环境看起来像一个胜利者在第一。

3)自托管:在这种情况下,这完全取决于你做任何你需要做的托管和运行服务

如果你扔出去选项#1,现在(如果你只有IIS6可用,我一直使用自托管),这是下降到IIS7与自我托管。

IIS7为您提供激活需求,如您的服务code不是在内存中在所有时间,但会被加载并初始化一次请求到来。这可以是一个加号。

在另一方面,托管在IIS7 / WAS剥夺你指定自己的终端的能力 - 你的终端,因此服务地址是你的MyService.svc文件所居住的虚拟目录 - 周期。你不能改变以任何方式,形状或形式。

自托管看起来像很多工作 - 但它确实给你最好的灵活性:你可以选择你的协议,只要你喜欢,你可以建立自己的解决方案,你喜欢的方式,你必须总控制什么得到执行的时候。如果你需要做一些额外的工作来托管服务,你可以介绍自己的自定义的ServiceHost,等等。

除非你只是与WCF打了一下周围,我总是推荐并投票支持自托管 - 如果你需要有WCF服务运行在任何时候,里面的Windows NT服务(这是最好的解决方案生产环境),如果你正在开发/调试,你完全可以在一个控制台应用程序,它可以启动和停止在您的休闲承载您的WCF服务。

因此​​,为了使长话短说:在最后,如果你真的想了所发生的事情的控制,我总是建议自托管

本的可能的变化,一旦新的都柏林服务器插件由微软出来 - 后一段时间.NET 4的推出,2010年可能是早期的 - 但仍然为时过早

希望这有助于。

马克·

So I'm designing a WCF service. I'm unexperienced with WCF, and I'm trying to decide whether it should be hosted in IIS, or a custom Windows service.. Or some other option?

Things to consider:

  • It needs to load data from a database on startup.
  • It needs to maintain this data across requests, not load it each time.
  • It needs to process multiple requests simultaneously.
  • It needs to be as configurable as possible regarding endpoints.
  • It will be calling native dlls quite a lot.

I suspect hosting it in IIS would simplify certain things, but I'm not sure it would be a good idea in this situation.

What are my options, and what are their pros and cons?

解决方案

You need to basically look at three options:

1) Hosting in IIS6 (Windows Server 2003/2003 R2): in this scenario, you can only host HTTP protocols - nothing else. This is quite a limitation in itself, you cannot use e.g. netTcp for Intranet scenarios.

2) Hosting in IIS7 / WAS (Vista, Server 2008): this gives you more option in terms of protocols supported, and the hosting environment looks like a winner at first.

3) Self-hosting: in this scenario, it's totally up to you to do whatever you need to do to host and run your services.

If you throw out option #1 for now (if you only have IIS6 available, I'd always use self-hosting), it's down to IIS7 vs. self-hosting.

IIS7 gives you "activation on demand", e.g. your service code is not in memory at all times, but will be loaded and instantiated once a request comes in. That can be a plus.

On the other hand, hosting in IIS7/WAS robs you of the ability to specify your own endpoints - your endpoint and thus service address is the virtual directory where your "MyService.svc" file lives - period. You cannot change that in any way, shape or form.

Self-hosting might look like a lot of work - but it does give you the best flexibility: you can pick your protocols as you like, you can set up your own addressing scheme the way you like it, and you have total control over what gets done when. You can introduce your own custom ServiceHost if you need to do some extra work to host services, and so on.

Unless you're just playing around with WCF a bit, I would always recommend and vote for self-hosting - if you need to have the WCF service running at all times, inside a Windows NT Service (that's the best solution for production environments), and if you're developing/debugging, you can totally host your WCF services in a console app which you can launch and stop at your leisure.

So to make a long story short: in the end, if you really want control over what's happening, I would always recommend self-hosting.

This might change once the new "Dublin" Server-Addon by Microsoft comes out - sometime after .NET 4 is launched, probably early in 2010 - but that's still too early to tell.

Hope this helps.

Marc

这篇关于我应承载在IIS中我的WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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