为WCF REST和ASP.NET Web API共享相同的端口
我有一个使用WCF webhttpbinding实现的基于JSON的现有服务.该服务托管在Windows服务中.我们还实现了SSL.现在,我计划使用ASP.NET Web API创建新的基于JSON的服务,该服务应托管在Windows服务中.但是问题在于客户端位于防火墙后面,它们无法向世界公开许多端口,因此我必须重用已经打开的端口.我知道这不可能直接实现.但是有什么解决方法可以使用相同的端口来处理WCF REST和ASP.NET Web API的请求吗?
I've an existing JSON based service implemented using WCF webhttpbinding. This service is hosted in Windows service. We've implemented SSL as well. Now I'm planning to create new JSON based services using ASP.NET Web API which should be hosted in windows service. But the problem is the clients are behind firewalls and they cannot expose many ports to world and so I've to reuse the already opened port. I'm aware this is not possible straight. But is there any workaround we could use the same port for handling requests comes to WCF REST and ASP.NET Web API?
I'm not interested to create any additional WCF router for that.
只要路径不同,WCF REST和Web API都可以共享同一端口.
Both WCF REST and Web API can share the same port as long as the path is different.
例如,
// 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");
}
WCF和Web API均成功运行并在端口13375进行侦听.在后台,该端口共享由HTTP.SYS模块负责.
Both the WCF and Web API ran successfully and listen at port 13375. Under the hood this port sharing is taken care by HTTP.SYS module.