简体   繁体   English

为什么/如何将自托管WCF服务迁移到IIS7?

[英]Why/how to migrate self-hosted WCF service to IIS7?

I've written some WCF services, which for development & debugging purposes I ran as self-hosted. 我编写了一些WCF服务,出于开发和调试的目的,我以自托管方式运行。 Now I've got a web server up and I'm considering whether there is any reason to change my services to run under IIS 7... and if so, how?.. 现在我有一个Web服务器,我正在考虑是否有任何理由改变我的服务在IIS 7下运行...如果是这样,怎么样?

MSDN has an article that explores the different WCF hosting models. MSDN有一篇文章探讨了不同的WCF托管模型。 Here is what it has to say about Self Hosting: 以下是关于自托管的说法:

The following are the advantages of self-hosting: 以下是自托管的优点:

  • Is easy to use: With only a few lines of code you have your service running. 易于使用:只需几行代码即可运行您的服务。
  • Is flexible: You can easily control the lifetime of your services through the Open() and Close() methods of ServiceHost. 灵活:您可以通过ServiceHost的Open()和Close()方法轻松控制服务的生命周期。
  • Is easy to debug: Debugging WCF services that are hosted in a self-hosted environment provides a familiar way of debugging, without having to attach to separate applications that activate your service. 易于调试:调试托管在自托管环境中的WCF服务提供了一种熟悉的调试方式,而无需连接到激活服务的单独应用程序。
  • Is easy to deploy: In general, deploying simple Windows applications is as easy as xcopy. 易于部署:通常,部署简单的Windows应用程序就像xcopy一样简单。 You don't need any complex deployment scenarios on server farms, and the like, to deploy a simple Windows application that serves as a WCF ServiceHost. 您不需要在服务器场等上使用任何复杂的部署方案来部署用作WCF ServiceHost的简单Windows应用程序。
  • Supports all bindings and transports: Self-hosting doesn't limit you to out-of-the-box bindings and transports whatsoever. 支持所有绑定和传输:自托管不会限制您开箱即用的绑定和传输。 On Windows XP and Windows Server 2003, IIS limits you to HTTP only. 在Windows XP和Windows Server 2003上,IIS仅限于HTTP。

The following are the disadvantages of self-hosting: 以下是自托管的缺点:

  • Limited availability: The service is reachable only when the application is running. 可用性有限:只有在应用程序运行时才能访问该服务。
  • Limited features: Self-hosted applications have limited support for high availability, easy manageability, robustness, recoverability, versioning, and deployment scenarios. 功能有限:自托管应用程序对高可用性,易管理性,健壮性,可恢复性,版本控制和部署方案的支持有限。 At least, out-of-the-box WCF doesn't provide these, so in a self-hosted scenario you have to implement these features yourself; 至少,开箱即用的WCF不提供这些,因此在自托管方案中,您必须自己实现这些功能; IIS, for example, comes with several of these features by default. 例如,IIS默认带有其中一些功能。

Good suggestion. 好建议。 Here are the exact steps I used to convert self-hosted to IIS hosted: 以下是我用于将自托管转换为IIS托管的确切步骤:

Step 1: Create .NET Framework 4 WCF Service Application 步骤1:创建.NET Framework 4 WCF服务应用程序
Step 2: Add Reference to the WCF DLLs. 第2步:添加对WCF DLL的引用。
Step 3: Right click on Service1.scv (auto-generated) and select "View Markup" Should look like this: code<%@ ServiceHost Language="C#" Debug="true" Service="WcfService4.Service1" CodeBehind="Service1.svc.cs" %>code. 步骤3:右键单击Service1.scv(自动生成)并选择“View Markup”应如下所示:code <%@ ServiceHost Language =“C#”Debug =“true”Service =“WcfService4.Service1”CodeBehind =“ Service1.svc.cs“%>代码。
Step 4: replace "...Service1" with the services from the DLLs. 步骤4:将“... Service1”替换为DLL中的服务。 Remove the tag CodeBehind="Service1.svc.cs". 删除代码CodeBehind =“Service1.svc.cs”。
Step 5: Right click on solution, Publish to your sever/page. 步骤5:右键单击解决方案,发布到您的服务器/页面。 Enable "Mark as IIS...". 启用“标记为IIS ...”。
Step 6: open yourserver/yourpage/Service1.scv 第6步:打开yourserver / yourpage / Service1.scv

If it ain't broke :) 如果没有破坏:)

Seriously: Don't do net.tcp WCF in IIS. 说真的:不要在IIS中执行net.tcp WCF。 Save you a lot of headaches. 给你带来很多麻烦。 HTTP WCF should be fine. HTTP WCF应该没问题。

I would consider creating a new project using VS2010's "WCF Service Application" project template. 我会考虑使用VS2010的“WCF服务应用程序”项目模板创建一个新项目。 You could even just reference your original assembly I suppose. 你甚至可以参考我想的原始组件。 Point is, if you use that template, VS2010 shows a new toolbar that allows you to publish to an IIS server that does all the "hard work" of creating the right config files and folders. 重点是,如果您使用该模板,VS2010会显示一个新工具栏,允许您发布到IIS服务器,该服务器可以完成创建正确配置文件和文件夹的所有“艰苦工作”。

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

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