This is a mirror of official site: http://jasper-net.blogspot.com/

RESTful WCF Architecture – Hosting RESTful WCF Services in IIS

| Tuesday, June 8, 2010
Hosting in IIS [managed hosting] offers the following advantages:

Process setup and shutdown.
Process pooling and recycling.
Application restart [recycle] when configuration changed.
Enhanced security model.
Management tools.
Caching management.
Proven hosting platform written, debugged by A-team @MS.
Officially supported MS product/technology.
Hosting WCF in IIS – Quick & Dirty

Following are quick steps to expose WCF service via IIS and svc file using Visual Studio.

Create ASP.NET Empty Web Application. The application will provide a container for RESTful WCF services – files with svc extension. When IIS receives a request to resource with svc extension it routes to WCF handler. Look for *.svc extension as a path and its corresponding handler which is System.ServiceModel.Activation.HttpModule in IIS manager under Handler Mappings.
Add WCF Service. Visual Studio creates three files. For example, if you create RESTfulWCF service these files are created:
RESTfulWCF.svc – the file that glues the request routed by IIS and the service implementation. This is a simple text file that should look similar to this:

<%@ ServiceHost Language="C#"
               Debug="true"
               Service="RESTfulWCFHostedInIIS.RESTfulWCF"
               CodeBehind="RESTfulWCF.svc.cs" %>

IRESTfulWCF.cs – service’s interface with contract attributes decoration. It’s a common WCF practice to separate the interface and the implementation when building WCF services.
RESTfulWCF.svc.cs – the code behind file that implements the service based on the IRESTfulWCF.cs.
Configure web.config.
Hosting WCF in IIS – Componentaized Approach

Another approach is to componentize the service into separate assembly. The main benefit of the approach is complete separationg or componentization of the service and how it’s exposed to the external world. Another huge benefit is this approach eliminates the need of messing with web.config.

Following are the steps needed to expose the WCF component that implements RESTful WCF service via svc file hosted in IIS:

Summary of steps:

Step 1 - Create class library project.
Step 2 - Implement RESTful resource.
Step 3 - Define RESTful WCF service interface.
Step 4 - Implement RESTful WCF service based on the interface.
Step 5 - Create empty web project.
Step 6 - Create new svc file.
Step 7 - Edit web.config file.
Step 8 - Test RESTful WCF service hosted in IIS.
Rest of the post is the detailed walkthrough of the above steps.

Read more: Alik Levin's

Posted via email from jasper22's posterous

0 comments: