Customizing IIS ServiceHost via ServiceHostFactory

When hosting in an IIS server, the WCF service and endpoints configuration are, by default, loaded from the Web.config file. So, developers do not need to explicitly create and initiate the ServiceHost like we do in a self-hosting scenario. Sometimes, however, we still need to customize the service or endpoints through code. This recipe will use a custom metadata configuration case to demonstrate how to programmatically adjust service behaviors in an IIS-hosting scenario.

How to do it...

Here we will go through the steps of applying a customized ServiceMetadataBehavior into an IIS-hosted WCF service:

  1. Create the WCF service in the hosting web application.

    We can simply create a new WCF service by ...

Get Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.