Routing WCF services by code

When you want to route the requests to specific WCF service deppending on the url, you can add routers on the Application_Start method of the Global.asax.cs. In the following example I want my ProductionService handle the service calls on the path starting with /Production/ and my PublicService handle the requests with a path starting with /public/demo/

using System;
using System.Web.Routing;
using System.ServiceModel.Activation;

public class Global : System.Web.HttpApplication
void Application_Start(object sender, EventArgs e)
#region Register Routes
var factory =
new WebServiceHostFactory();
new ServiceRoute("Production", factory, typeof(ProductionService)));
new ServiceRoute("Public/demo/", factory, typeof(PublicService)));

Author: Pouya Panahy

Microsoft certified DevOps engineer with passion in analysing, designing and implementing solutions for Azure Cloud with hands-on experience in security and quality assurence.

Leave a Reply