This project is read-only.


Topics: Web Api
Apr 26, 2011 at 2:36 AM

I found HttpServiceHostFactory but it didn't seem to be used in any samples. What's it's state of readiness and what's is functionality. 

Apr 26, 2011 at 2:51 AM
Edited Apr 26, 2011 at 2:51 AM

It is very stable. The difference between it and HttpConfigurableServiceHostFactory (which MapServiceRoute / samples use) is the latter provides a fluent api / configuration class that you can reuse and better hooks for using things like IoC containers. It's in the samples to get feedback on the approach as we are looking down that path.

HttpServiceHostFactory exposes two factories on it, MessageHandlerFactory and OperationHandlerFactory our two key extensibilty points. You can directly use it. If you want to use it with ASP.NET routes you can new up a ServiceRoute passing in an HttpServiceHostFactory instance and adding that to your routes.

I would expect many of the concepts related to configuration to ultimately merge in to HttpServiceHostFactory. Currently it is more exploratory.

Make sense?



Apr 26, 2011 at 3:55 PM

Yes that does make sense.

The reason I asked is because I also found HtmlPageBuilder and traced it back to that class. I have yet to use that class, but it looks interesting.

Apr 26, 2011 at 7:13 PM

Can we get some sample code for MapServiceRoute that uses more complex routes than the trivial examples like "contact" and "contacts"? For example, something like "mainfolder/subfolder/contacts". I have not been able to get the more complex, nested routes to work. WebServiceHostFactory3 seems to handle complex routes just fine though.

Apr 26, 2011 at 8:00 PM

I also had a question on ordering. When I register routes in this order they work correctly

         RouteTable.Routes.MapServiceRoute<EntityGenerationService>("xsd", configuration);
         RouteTable.Routes.MapServiceRoute<DirectoryListingResource>("", configuration);

If I change the order to the following then "ContactResource" and the "xsd" routes give me a file not found error
RouteTable.Routes.MapServiceRoute<DirectoryListingResource>("", configuration);
RouteTable.Routes.MapServiceRoute<EntityGenerationService>("xsd", configuration);

Apr 26, 2011 at 9:04 PM

Hi cb55555

When you say it works just fine do you mean passing WebServiceHostFactory3 to a ServiceRoute, or not using routing at all? Can you put a repro somewhere where I can grab it / email it to me?



Apr 26, 2011 at 9:35 PM

Hi Glenn,

I posted some code in this thread:

Let me know if you need any more details.

Apr 26, 2011 at 10:14 PM

Can you try using HttpServiceHostFactory with your route instead of the WebServiceHostFactory3?

This may be bug in the HttpConfigurableServiceHost.


Apr 26, 2011 at 11:21 PM

Yup. That worked. Thanks!

Apr 26, 2011 at 11:25 PM

OK, then it is likely not a bug in our core bits but in the enhancments add-on. I will look into it.



Apr 27, 2011 at 5:08 PM

Well, it turns out that HttpServiceHostFactory wasn't the fix. When I initially tested the routing with HttpServiceHostFactory, I unintentionally ran it using the VS development server, so the host name was localhost:portnum, and the application root was http://localhost:portnum/. I usually test using my local IIS 7.5. When running from IIS, the path to the application root is http://localhost/webappname/. (Note: the application virtual folder.) This is the scenario that RouteTable.Routes.MapServiceRoute can't handle.

I even tried prefacing the route with the application virtual folder name, it still doesn't work.

Apr 28, 2011 at 3:11 PM

Glenn, I want to make sure you see my post about a potential bug with handling routes with applications deployed in virtual folders in IIS.

Aug 18, 2011 at 9:51 PM

Hi all,    


I ran into the same problems, I've published the web api into a virtual directory (shared environment) and I get an 404 when I do a request, local it works. (RouteTable.Routes.MapServiceRoute<ProductResource>("products", configuration); )

Is there already a workaround, otherwise I've a big problem.


Thanks for the feedback.

Aug 18, 2011 at 10:14 PM

Ok problem solved! I added following to my web.config

    <modules runAllManagedModulesForAllRequests="true">
        <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

And added multipleSiteBindingsEnabled -> <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"  />