This project is read-only.

.config file based configuration

Topics: Web Api
Aug 5, 2011 at 3:02 AM

Are there any examples of configuring a service via configuration file rather than the Fluent interface? I saw the config files in the Microsoft.ApplicationServer.Http.CIT.Unit test project, but they don't show things such as adding channels and handlers.

Aug 5, 2011 at 6:34 AM

Yes, there are several possibilities.

If you don't need to use the IoC hooks, you can just new up an HttpServiceHostFactory. It has 2 properties on it, OperationHandlerFactory and MessageHandlerFactory which you can set.

  • For the operation handler factory, you derive from HttpOperationHandlerFactory to create one. It has 2 methods one for request handlers and the other for response handlers.
  • To set formatters, you access the Formatters collection hanging off the factory. You can set this within the constructor of the factory or external as it is a public property
  • To set handlers, you create an instance of HttpMessageHandlerFactory passing the handler types in the ctor.

Next you can register the factory by creating a new ServiceRoute passing in the service type and the factory. You then add that directly to the route collection.

if you want to take advantage of the IoC hook that we added, then you should create an instance of HttpHostConfiguration. The fluent api is just syntactic sugar which configures this object. It exposes properties for OperationHandlerFactory, MessageHandlerFactory and ResourceFactory.

You can then use the MapServiceRoute extension method to pass in the configuration object.