tags:

views:

453

answers:

1

I would like to make a RESTful app of HTTPhandlers without having to define every endpoint by making an entry in the web.config, i'd like the style of attaching attributes to a class constructor eg:

public class obj : IHttpHandler
{
  [WebGet(UriTemplate = "/accounts/{id}")]
  public obj(string id)
  {
     // this is just an eg, it worild normally include caching and 
     // a template system
     String html = File.ReadAllText("/accounts/accounts.htm");
     html.replace("id", id);
     httpcontext.current.response.write(html)
  }
}

instead of

<httpHandlers>
      <clear />
      <add verb="GET" path="/accounts/*" type="MyApp.obj" />
</httphandlers>

The way i'm doing it now i have 100's of endpoints in the web.config :( i'd rather define them in the class. And i don't want to make extra files (.asmx) either. I'd like an app of just .htm files with tokens and .cs files

Thanks!

+1  A: 

You could automate the registration of the endpoints and so on, with a custom ServiceHost, which overrides the ApplyConfiguration() method, which then virtualizes the configuration so that it does not have to be in the web.config file.

Here's a starting point. It doesn't do exactly what you want, but it illustrates the concept of virtualizing the configuration.

Cheeso
This looks like the way to go, ServiceHostBase.AddServiceEndpoint Method (String, Binding, Uri) Thank you!
rizzle