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

发布于 2024-08-13 16:37:06 字数 322 浏览 3 评论 0原文

我想公开我的服务层(目前使用 POCO 编写为标准类库)以供外部和内部使用。外部客户端将通过 REST 样式 API 使用它,而在内部我的 MVC 应用程序将通过 net.tcp 绑定使用它以获得更好的性能。

我该如何优雅地做到这一点?我可以编写 2 个包装器,其中一个使用 VS2010 Beta 2 REST 功能用于 REST,另一个使用标准 WCF 绑定。

我可以在一个包装中完成此操作吗?或者更好的方法是将我现有的服务重构为 WCF 并使用不同的绑定(如 WebHTTPBinding、WsHttpBinding 等)在各种端点上公开。

问候,

Ajay

I want to expose my Service Layer (which is currently written as standard class library with POCOs) for external as well as internal consumption. External clients will use it over REST style APIs while internally my MVC app will use it over net.tcp binding for better performance.

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.

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.

Regards,

Ajay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆悲凉 2024-08-20 16:37:06

您的服务库将仅包含服务的实现 - 您的服务(和数据)合同应位于其自己单独的“合同”程序集中。

托管和使用什么协议的问题由您的服务主机处理 - 这可以是 IIS 或单独的 NT 服务或控制台应用程序或其他东西。这完全独立于您的服务类别和服务库。

所以是的 - 您可以轻松创建一个服务库,然后通过服务主机中的多个端点公开该服务 - 这两件事应该保持完全独立。

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. 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.

瞳孔里扚悲伤 2024-08-20 16:37:06

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

Sure you can just add more of them to the configuration file or using the code.

愛放△進行李 2024-08-20 16:37:06

VS 2010 Beta 2 的 REST 功能本身是构建在 WCF 之上的,因此如果您想使用它们,无论如何您都必须将您的服务重构为 WCF 服务。那时,正如 Dani 和 marc_s 所说,您可以非常轻松地通过配置文件向服务添加其他端点。

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. At that point, as Dani and marc_s say, you can very easily add additional endpoints to the service through the configuration file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文