Monday, July 20, 2009

Hosting a WCF Service Library in IIS



STEP 1
Create your service library project and code up your service. I am assuming that you know how to do this. For my example I am simply going to use what comes out of the box when you create a new service library project in Visual Studio 2008. To follow along create a new service library project in Visual Studio 2008 and name it HostingServiceLibraryIIS.

Step 2
create an svc file (use text file as the type) in the project named whatever you like. I will name mine “sample.svc”.

Add this single line to the top of the file:
<% ServiceHost Service=”HostingServiceLibraryIIS.Service1” %>
where your class that holds your service implementation is listed in place of "HostingServiceLibraryIIS.Service1".


Step 3
Add a configuration file to your project and name it web.config. Paste the contents of the "system.serviceModel" section from the App.config file that was included by default in the library project into the web.config file between the opening and closing "configuration" tags.

Step 4
Create a new application in IIS and point it at the folder that contains your project files. Make sure that your project is building to the bin folder and not bin/Debug or bin/Release.

That’s it! You should now be able to browse to your svc file in IIS and see your service in action.

No comments: