DynamicWCFServicesHoster

June 14th, 2007 Version 1.2 Pascal Belaud Microsoft France

Introduction

DynamicWCFServicesHoster is a windows service that allows you to host all your Windows Communication Foundation services automatically. All you have to do is to provide a regular XML configuration file with the classical <system.serviceModel /> entries you are used to use and DynamicWCFServicesHoster will do the hosting for you.

Updated information is available at:
http://www.MsFranceDev.net/DynamicWCFServicesHoster

Latest build, including this documentation, is available at:
http://www.MsFranceDev.net/DynamicWCFServicesHoster/DynamicWCFServicesHoster.zip

Installation

Copy the windows server DynamicWCFServicesHoster.exe anywhere on your computer. We are going to assume that this file is located in the following directory:

C:\Program Files\DynamicWCFServicesHoster

We are going now to install once for good this application as a Windows service. Open a command console, as an administrator, and type the following:

"%windir%\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe" "C:\Program Files\DynamicWCFServicesHoster\DynamicWCFServicesHoster.exe"

You are now ready to use this service to host all your WCF services:

Hosting your WCF services

In order to host your WCF services (using any techniques), you know that you need to create an XML configuration and specify all the WCF information needed by the WCF runtime. You can create this configuration file by hand or by using the WCF Configuration Editor located in the Windows SDK tools directory:

This is no different when using DynamicWCFServicesHoster.

As an example, lets say that we have two different WCF contracts, WCFInterfaces1.IService1 and WCFInterfaces2.IService2, in two different assemblies. Those contracts are implemented in two different classes, WCFServices1. Services1 and WCFServices2. Services2, located in two others separate assemblies:

Assembly : WCFInterfaces1.dll

namespace WCFInterfaces1

{

[System.ServiceModel.ServiceContract]

public interface IService1

{

[System.ServiceModel.OperationContract]

void MyMethod();

}

}

 

Assembly : WCFServices1.dll

namespace WCFServices1

{

public class Services1 : WCFInterfaces1.IService1

{

public void MyMethod()

{

EventLog.WriteEntry("WCFServices1.Services1", "MyMethod", EventLogEntryType.Information);

}

}

}

 

Assembly : WCFInterfaces2.dll

namespace WCFInterfaces2

{

[System.ServiceModel.ServiceContract]

public interface IService2

{

[System.ServiceModel.OperationContract]

void MyMethod();

}

}

 

Assembly : WCFServices2.dll

namespace WCFServices2

{

public class Services2 : WCFInterfaces2.IService2

{

public void MyMethod()

{

EventLog.WriteEntry("WCFServices2.Services2", "MyMethod", EventLogEntryType.Information);

}

}

}

Using the SvcConfigEditor tool, we are going to configure the DynamicWCFServicesHoster windows service to host automatically our two services.

We are going now to declare the two services. Service1 will be available via netTcpBinding and Service2 will be available via basicHttpBinding:

If you try to start the DynamicWCFServicesHoster windows service, you will notice that it wont start and taking a look at the Application EventLog will give you a hint of what is going on:

The error message is pretty clear. Everything is just fine except the fact that the DynamicWCFServicesHoster windows service has no idea where to load the assemblies from. You will need to supply this information in the <appSettings> section of the XML configuration file. You can do this using any XML file manipulation tool. In my case, Im using XML Notepad 2007:

which end up with the following XML:

Now you should be able to successfully start the windows service:

This is will be confirmed by the entry in the Application EventLog that should look like this:

Now you are ready to call your WCF services from any client application!