SetOperationHandlerFactory doesn't work?

Topics: Web Api
May 1, 2011 at 3:10 PM

My operation handler factory is never called:

 

public static void RegisterRoutes(RouteCollection routes)
{
    var config = HttpHostConfiguration.Create().SetOperationHandlerFactory<JsonNetOperationHandlerFactory>();

    routes.MapServiceRoute<UserResource>("user", config);
}

private class JsonNetOperationHandlerFactory : HttpOperationHandlerFactory
{
    public JsonNetOperationHandlerFactory()
        : base(new[] { new JsonNetFormatter() })
    {
    }

    protected override System.Collections.ObjectModel.Collection<Microsoft.ApplicationServer.Http.Dispatcher.HttpOperationHandler> OnCreateRequestHandlers(System.ServiceModel.Description.ServiceEndpoint endpoint, HttpOperationDescription operation)
    {
        return base.OnCreateRequestHandlers(endpoint, operation);
    }

    protected override System.Collections.ObjectModel.Collection<Microsoft.ApplicationServer.Http.Dispatcher.HttpOperationHandler> OnCreateResponseHandlers(System.ServiceModel.Description.ServiceEndpoint endpoint, HttpOperationDescription operation)
    {
        return base.OnCreateResponseHandlers(endpoint, operation);
    }
}
May 2, 2011 at 2:19 AM

Hi Daniel,

I took your HandlerFactory and added it to the HttpHelloResource sample and the factory did get called.  Only the constructor gets called at startup though.  The OnCreateRequestHandlers and OnCreateResponseHandlers only get called one you make a request that needs a formatter.