Sharing the same port for WCF REST and ASP.NET Web API

I have an existing JSON based service implemented using WCF webhttpbinding. This service is hosted on a Windows service. We have also implemented SSL. Now I plan to create new JSON-based services using the ASP.NET Web API, which should be hosted in a Windows service. But the problem is that clients are behind firewalls, and they cannot expose many ports in the world, and therefore I must reuse an already open port . I know that this is impossible directly. But is there any workaround that we could use with the same port to handle requests that goes into WCF REST and ASP.NET Web API?

EDIT: I'm not interested in creating additional WCF routers for this.

+4
source share
1 answer

Both WCF REST and Web APIs can share the same port if the path is different.

For instance,

// Starting WCF service in port 13375 (Running in Process 1)
ServiceHost wcfServiceHost = new ServiceHost(typeof(StaffIntegrationService));
wcfServiceHost.addServiceEndPoint(typeof(IStaffIntegrationService), webHttpBinding, "http://localhost:13375/wcf");
wcfServiceHost.open();


// Start WebAPI in 13375 (Running in Process 2)
using (WebApp.Start<Startup>(url: "http://localhost:13375/api"))
{
   Console.WriteLine("Service is started");
}

Both WCF and the web API worked successfully and listened on port 13375. Under the hood, the HTTP.SYS module takes over this port exchange.

+3
source

All Articles