HttpHostConfiguration

Topics: Web Api
Nov 1, 2011 at 3:35 PM

I don't see HttpHostConfiguration class as part of Microsoft.ApplicationServer.HttpEnhancements dll. Any reason why i am missing this.

Coordinator
Nov 1, 2011 at 3:43 PM

The new configuration class in Preview 5 is HttpConfiguration. There is also an “enhanced” version in the Web API enhancements called WebApiConfiguration.

Daniel Roth

Nov 1, 2011 at 4:10 PM

Hi,

I have a custom message handler for doing api key verification. I am using CastleWindsor as my IOC container. I am registering my types in castle Windsor.  Below is my constructor code . It is telling me that HttpMessageHandler is not registered. How i can resolve this. urgent help is appreciated.

public ApiVerificationHandler(HttpMessageHandler innerHandler, IVideoRepository repository) :base(innerHandler){             _repository = repository;         }

container.Register(Component.For<ApiVerificationHandler>());
configuration.MessageHandlerFactory = (() => new DelegatingHandler[] {(DelegatingHandler) container.Resolve(typeofApiVerificationHandler))}); 

Thanks in advance.
Coordinator
Nov 1, 2011 at 4:44 PM

How are you registering the configuration object? Are you using MapServiceRoute? Are you in IIS/ASP.NET or self-host?

Nov 1, 2011 at 6:11 PM

Yes I am using the MapServiceRoot metthod. i am using asp.net MVC as the host process. and using the below line to set configuration to all the routes.

RouteTable.Routes.SetDefaultHttpConfiguration(configuration);
Coordinator
Nov 1, 2011 at 8:08 PM

Is the error you are getting from Castle Windsor i.e. Windsor is telling you the handler is not registered?

Glenn

Nov 2, 2011 at 9:35 AM

Yes i am getting the error from castle Windsor

Below is the error info.

Can't create component 'Castle.WCF.WebApi.Handlers.ApiVerificationHandler' as it has dependencies to be satisfied.

Castle.WCF.WebApi.Handlers.ApiVerificationHandler is waiting for the following dependencies:

Services:
- System.Net.Http.HttpMessageHandler which was not registered.

Code block

var configuration = new WebApiConfiguration();
            
  var container = InitializeContainer();
  RouteTable.Routes.SetDefaultHttpConfiguration(configuration);

           
  configuration.MessageHandlerFactory = (() => new DelegatingHandler[] {(DelegatingHandler) container.Resolve(typeofApiVerificationHandler))});
 configuration.CreateInstance = ((type, requestMessage, o) => container.Resolve(type));
RouteTable.Routes.MapServiceRoute<VideoResource>("Videos");


 private IWindsorContainer InitializeContainer()
        {
            container = new WindsorContainer();
            container.Register(Component.For<VideoResource>().LifeStyle.Transient);
            container.Register(Component.For<IVideoService>().ImplementedBy<VideoService>());
            container.Register(Component.For<IVideoRepository>().ImplementedBy<VideoRepository>());
            container.Register(Component.For<IKeyVerifierService>().ImplementedBy<KeyVerifierService>());
            container.Register(Component.For<ApiVerificationHandler>());
            return container;
        }
 
 
Nov 3, 2011 at 8:01 AM

Your ApiVerificationHandler cannot be resolved by windsor becuase HttpMessageHandler has not been registered into the container and neither you can register it...

Keep in mind in prev 5 MessageHandler does no longer required HttpMessageHandler in the constructor.

I assume if you update your ApiVerificationHandler to

public ApiVerificationHandler( IVideoRepository repository){...}

windsor will resolve it: it works with no problem for me

Coordinator
Nov 3, 2011 at 8:12 AM

doh, great catch!

Yes, in the past we required the message handler to get passed in as a param. We heard a lot of feedback that it made constructing handlers with an IoC either impossible or very hard depending on the container :-)

So in Preview 5, we removed the requirement for passing in that constructor dependnecy and made it be a property on the handler which our infrastructure automatically sets for you. That means you no longer have to worry about it.

So as crixo72 said....get rid of the handler on the ctor and you should be golden.

Nov 4, 2011 at 4:55 PM

Thanks guys,

It solved the problem