我有一个使用 WCF webhttpbinding 实现的现有基于 JSON 的服务。此服务托管在 Windows 服务中。我们也实现了 SSL。现在我计划使用 ASP.NET Web API 创建新的基于 JSON 的服务,该服务应该托管在 Windows 服务中。但问题是客户端在防火墙后面,它们不能向世界公开许多端口,所以我必须重用已经打开的端口 .我知道这是不可能的。 但是有什么解决方法我们可以使用相同的端口来处理来自 WCF REST 和 ASP.NET Web API 的请求?
编辑:我没有兴趣创建任何额外的 WCF router为了那个原因。
最佳答案
只要路径不同,WCF REST 和 Web API 都可以共享同一个端口。
例如,
// 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 模块负责。
关于asp.net-web-api - 为 WCF REST 和 ASP.NET Web API 共享相同的端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27988675/