为WCF REST和ASP.NET Web API共享相同的端口 [英] Sharing the same port for WCF REST and ASP.NET Web API

查看:64
本文介绍了为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.

这篇关于为WCF REST和ASP.NET Web API共享相同的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆