I've written some WCF services, which for development & debugging purposes I ran as开发者_JAVA百科 self-hosted. 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?..
MSDN has an article that explores the different WCF hosting models. 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.
- 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.
- Is easy to deploy: In general, deploying simple Windows applications is as easy as 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.
- 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.
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; IIS, for example, comes with several of these features by default.
If it ain't broke :)
Seriously: Don't do net.tcp WCF in IIS. Save you a lot of headaches. HTTP WCF should be fine.
I would consider creating a new project using VS2010's "WCF Service Application" project template. 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.
Good suggestion. Here are the exact steps I used to convert self-hosted to IIS hosted:
Step 1: Create .NET Framework 4 WCF Service Application
Step 2: Add Reference to the WCF DLLs.
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.
Step 4: replace "...Service1" with the services from the DLLs. Remove the tag CodeBehind="Service1.svc.cs".
Step 5: Right click on solution, Publish to your sever/page. Enable "Mark as IIS...".
Step 6: open yourserver/yourpage/Service1.scv
精彩评论