Hosting Options For Windows Communication Foundation (WCF) Services
WCF Services can be hosted in a number of ways depending on the need and required usage of the service.
Leveraging a Re-Useable WCF Service
Using Visual Studio 2008 you can quickly and easily build flexible WCF services that are hosting environment neutral. That is, build the web service as a library which can be re-used in a variety of hosting environments.
Testing your WCF service
Whilst you can use the svcutil client to test your service by invoking contract operations another approach is to build a simple console application. This same console application, acting as a client, can connect to any server hosted service with a bit of configuration (defined endpoints). The advantage of a console test program over the standard svcutil is that you can do more complex things before and after invoking service operations.
If creating a console application, simply create a new endpoint in your app.config file for each of the endpoints you plan on connecting to; e.g. a local service, windows service and web service.
namespace EnterpriseDotNet.MmoApplication { class MmoAccountApplication { static void Main(string[] args) { string heading = "===== Enterprise Dot NET - WCF Service and Client ======"; Console.WriteLine(heading); using (MmoAccountClient client = new MmoAccountClient("BasicHttpBinding_WebService")) { Console.WriteLine("This service is up and running and can now be accessed..."); Console.Write("Account from which to perform character selection: "); string account = Console.ReadLine(); Console.WriteLine("Retrieving characters..."); MmoCharacter[] characters = client.GetCharactersForAccount(account); Console.WriteLine(); Console.WriteLine("{0} character(s) found.", characters.Length); foreach (MmoCharacter character in characters) { Console.WriteLine("\t Character Name: {0}, Level: {1}", character.Name, character.Level); } } Console.WriteLine("Press any key to exit..."); Console.Read(); } } }
Sticking with the previous post on WCF this application uses the MMO login service. This app connects to a binding, and retrieves the characters for a given account.
Local hosting
The service is instantiated locally.
Hosting a WCF Service as a windows service
The main difference with a windows service is that typically you will provide an install project for installing the windows service using the installutil that comes with the .NET framework.
You can use installutil.exe path_to_service to install the service and installutil.exe -u path_to_service to uninstall it.
Once the service has been successfully installed, it’s simply a matter of ensuring the service has been started in “Windows Services”.
You can find more information on hosting a WCF Service as a Windows Service here.
Hosting a WCF Service within IIS
This can be achieved in a two step process. Firstly, the service can be hosted in a WCF Web project. Once setup, viewing the service in your browser you can verify that the service is being hosted within the ASP.NET development server. From there it is simply a matter of Setting up a new IIS application pool for the service.
You can find more information on the hosting WCF services in IIS 7 and Windows 2008 here.
Summary
With the use of a WCF service library I have presented three different hosting environments; local hosting, hosting as a windows service and hosting within IIS. WCF Service Libraries offer great flexibility with respect to how they can be invoked by providing a “drop in” deployment approach in a range of hosting environments. How clients are to consume the web service wil often define the best hosting option,

November 26th, 2008 at 5:27 pm
[...] two previous articles I looked at Information Dissemination with WCF Services and Hosting Options for Windows Communication Foundation Services. In a similar fashion I am going to use the MMO application domain already presented and use it as [...]