Pages

Wednesday, October 13, 2010

Converting Visual Studio 2010 Class Library Project to WCF Class Library Project

Overview

This may be a rather unique case, but there are instances where previous libraries begin to take advantage of the WCF attributes in order to expose business logic classes and libraries as WCF services.

This post will attempt to walk you through the process of converting an old class library project to a WCF service library project.


Scenario

Here is an example of a scenario where this applies: Acme company has a mid-tier class that was used in legacy .NET 1.0 applications in order to disable customers that are either delinquent on their bill or have broken the company's Terms of Service agreement. The new business needs require this to be implemented as a web service. We could accomplish this by creating a new interface for the class that utilizes the OperationContract and ServiceContract attributes (which were made available in .NET 3.0). Now the existing libraries are exposed as WCF interfaces. The next step is simply to create a host for the interface.

However, the project was originally created as a "Class Library" and, therefore, the developer notices now that he can't utilize the WCF Service Host that is available for projects that are created as a "WCF Service Library" project. The solution of converting the project type may not be simple, but is nonetheless possible. In the next section, I will describe how to convert a Visual Studio 2010 (and possibly lower versions as well, but not tested) from a basic "Class Library" project type to a "WCF Service Library" project type.