[英]ASP.Net Web API vs WCF - Can the Web API be used to provide REST-based communication to a singleton WCF service?
I have an existing set of singleton WCF services. 我有一套现有的单例WCF服务。 They are long-running processes that do a lot of work on an ongoing basis and expose themselves with WCF service contracts for communication with other processes. 它们是长期运行的流程,可以持续进行大量工作,并通过WCF服务合同展示自己与其他流程进行通信。
When the WCF Web API was being developed I was excited because it was looking like I'd finally be able to do away with all of the annoying contract stuff and simply provide a platform-agnostic REST API for each service and have the processes communicate via HTTP requests and JSON responses. 在开发WCF Web API时,我感到非常兴奋,因为看起来我终于可以取消所有烦人的合同内容,只需为每个服务提供与平台无关的REST API,并让流程通过HTTP请求和JSON响应。
Now it looks like the Web API has become an IIS-hosted ASP.Net feature, leaving me trying to figure out if I'm just missing something or if my WCF services will no longer have the opportunity to provide a REST interface. 现在看起来Web API已经成为一个IIS托管的ASP.Net功能,让我试图弄清楚我是否只是遗漏了一些东西,或者我的WCF服务将不再有机会提供REST接口。
If the Web API is no longer really targeted at my scenario, what has the ASP.Net team envisioned with respect to non-terminating singleton processes that wish to provide an HTTP/JSON-based API to other consuming processes? 如果Web API不再真正针对我的场景,那么ASP.Net团队对于希望为其他消费流程提供基于HTTP / JSON的API的非终止单例进程设想了什么?
You do not have to host ASP.NET Web API services in IIS. 您不必在IIS中承载ASP.NET Web API服务。 There is an option called " Self Hosting " that will allow you to host your API services in another process (such as a Windows Service) if you would like. 有一个名为“ Self Hosting ”的选项,如果您愿意,它允许您在另一个进程(例如Windows服务)中托管您的API服务。 I imagine that your current architecture would work just fine as a self-hosted app. 我认为您当前的架构可以作为自托管应用程序正常工作。
You can self-host using ServiceHost
as in this MSDN example . 您可以使用ServiceHost
进行自托管, 如此MSDN示例中所示 。 See related SO post . 查看相关的SO帖子 。 Essentially - IIS is not a requirement for WCF hosting. 本质上 - IIS不是WCF托管的必要条件。
If you are using webHttpBinding
- you just need to create the WebServiceHost
which extends from ServiceHost
to support REST. 如果您正在使用webHttpBinding
- 您只需要创建从ServiceHost
扩展到支持REST的WebServiceHost
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.