What is the difference between defining web.config endpoints and registering global.asax routes?

332 views Asked by At

What is the difference between defining endpoints in web.config and registering routes in global.asax (for the services) like the following:

protected void Application_Start(object sender, EventArgs e)    
{    
    RouteTable.Routes.Add(
        new ServiceRoute(
            "", 
            new WebServiceHostFactory(), 
            typeof(PersonService)
        )
    );    
}
1

There are 1 answers

0
carlosfigueira On

As far as the runtime goes, the endpoints are the same. But for IIS-hosted services, if you don't use routes, then the endpoint address will always have the .svc in them - i.e., http://your-computer/app/service.svc/endpoint1. Some people don't like it, especially for REST services, where the .svc doesn't belong in pure URLs.

The drawback of using routes is that you need to use the ASP.NET pipeline, which is a problem for some services (IIRC it has a small performance penalty, and by default WCF services don't allow it, you need to explicitly allow the ASP.NET compatibility mode).