How To: Integration of WCF with Autofac

If you’d like to hide WCF implementation class behind an interface to simplify future changes you should deal with some IoC. I use Autofac and have several times struggled upon the same point when trying to configure WCF to work with it. This trouble begins when you end up with failed service and message “The service configured for WCF is not registered with the Autofac container”.

Here I’d like to describe which points should be taken into account when configuring the service, but before that I’d like to add more context about using of the service.

The service is host in WAS. On the picture below you can see how the service is consumed by an application. The answer to question “why is it so?” lays out of the text scope, but I’d like to point out that Autofac configuration for WCF is located only in the WCF package.

WCF behind an interface with a custom proxy class

Now you can find error which might appear during configuration and steps to solve them.

Metadata publishing for this service is currently disabled

This message most likely means you don’t have correct entry in web.config file. You should check that it has the following:

So WCF.Service represent the full service class name. Contracts.IService represents the full interface name. This entry should be placed in the section <system.webServer> at any place of its child section <system.serviceModel>. More about metadata on MSDN:

The service configured for WCF is not registered with the Autofac container

This is the main subject of the text and there are two points to remember. First of all, the markup file should have a correct information about interface, and the second, the interface and the client should be located in the same assembly.

The main point is the structure of the attribute Service. You should write there a full interface name and full assembly name where the interface is located. In general case the assembly name should be the same as qualified in the project settings.

No Comments

You can leave the first : )

Leave a Reply