简体   繁体   English

WCF-在一个服务库上使用包括REST(WebHttpBinding)在内的多个绑定?

[英]WCF - using multiple bindings including REST (WebHttpBinding) on one service library?

I want to expose my Service Layer (which is currently written as standard class library with POCOs) for external as well as internal consumption. 我想公开我的服务层(目前已作为标准类库与POCO一起编写)供内部和外部使用。 External clients will use it over REST style APIs while internally my MVC app will use it over net.tcp binding for better performance. 外部客户端将通过REST风格的API使用它,而我的MVC应用内部将通过net.tcp绑定使用它以获得更好的性能。

How do I do this elegantly? 我如何优雅地做到这一点? I can write 2 wrappers one for REST using VS2010 Beta 2 REST features and other using standard WCF bindings. 我可以使用VS2010 Beta 2 REST功能为REST写2个包装,其他使用标准WCF绑定编写。

Can I do this in one wrapper? 我可以用一个包装纸做吗? or better just refactoring my existing services as WCF and expose on various endpoints using different bindings like WebHTTPBinding, WsHttpBinding, etc. 或者更好的方法是将现有服务重构为WCF,并使用WebHTTPBinding,WsHttpBinding等不同的绑定在各种端点上公开。

Regards, 问候,

Ajay 阿杰

Your service library will only contain the implementation of the service - your service (and data) contracts should be in their own separate "Contracts" assembly. 您的服务库将仅包含服务的实现-您的服务(和数据)合同应位于其自己的单独的“合同”程序集中。

The question of hosting and what protocol to use is handled by your service host - this can be IIS or a separate NT Service or a console app or something. 托管以及使用哪种协议的问题由您的服务主机处理-可以是IIS或单独的NT Service或控制台应用程序或类似的东西。 That is totally independant of your service class and your service library. 完全独立于您的服务类和服务库。

So yes - you can easily create a service library and then expose that service over a multitude of endpoints in your service host - those two things should be kept totally separate from one another. 所以是的-您可以轻松地创建一个服务库,然后在服务主机中的多个端点上公开该服务-这两项应该完全分开。

当然,您可以仅将它们中的更多添加到配置文件中或使用代码。

VS 2010 Beta 2's REST features are themselves built on top of WCF, so if you want to use them you'll have to refactor your service into a WCF service anyway. VS 2010 Beta 2的REST功能本身是基于WCF构建的,因此,如果要使用它们,则无论如何都必须将服务重构为WCF服务。 At that point, as Dani and marc_s say, you can very easily add additional endpoints to the service through the configuration file. 就像Dani和marc_s所说,到那时,您可以非常容易地通过配置文件将其他端点添加到服务中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM