按端点塑造 WCF 服务

发布于 2024-09-25 16:50:49 字数 340 浏览 4 评论 0原文

我有 2 个合约(cA 和 cB),由具有 2 个端点(epA 和 epB)的单个 WCF 服务实现。

不是出于安全目的,而纯粹是出于清晰/组织的原因,我只想在通过端点A发现服务时“看到”ContractA的操作;同样,只能通过端点B看到ContractB的操作。

我不需要“保护”这些操作本身。这种情况下,任何给定的客户端只需要服务的一侧,而不是两者(但是,操作本身共享资源,因此使用单个服务而不是两个服务是有意义的)。

似乎任何给定的服务基本上都会获得 1 个 WSDL,因此所有操作都会暴露给所有端点。这是它的工作方式吗,还是有办法通过阻止端点合约未定义的操作来“塑造”端点?

I have 2 contracts (cA & cB) implemented by a single WCF service with 2 endpoints (epA & epB).

This is not for security purposes, but purely for reasons of clarity/organization, I'd like to only "see" ContractA's operations when I discover the service via endpointA; and likewise, only see ContractB's operations via endpointB.

I don't need to "protect" these operations per se. The scenario is such that any given client only needs one "side" of the service, never both (but, the operations themselves share resources, so it makes sense to have a single service rather than 2 services).

It seems that any given service basically gets 1 WSDL, ergo all operations are exposed to all endpoints. Is that the way it works, or is there a way to "shape" an endpoint by occluding operations not defined by the endpoints contract?

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

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

发布评论

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

评论(2

向日葵 2024-10-02 16:50:49

默认情况下,您是对的 - 一个服务实现类获取一个 WSDL,其中包含该服务类实现的所有服务方法(来自所有服务契约)。

没有任何方法(据我所知)可以以任何(简单)方式“塑造”WSDL - WCF 确实提供了进入创建 WSDL 的过程(静态或动态)的方法,但这些方法不适用于胆怯的人。对您来说,将服务契约的实现拆分为两个单独的类会容易得多,然后您将拥有两个单独的服务、单独的 WSDL 等等。

By default, you're right - one service implementation class gets one WSDL which contains all service methods (from all service contracts) that this service class implements.

There are no ways present (as far as I know) to "shape" the WSDL in any (easy) way - WCF does offer ways to get into the process of creating the WSDL (statically or dynamically), but those aren't for the faint of heart. It would be much easier for you to just split the implementation of the service contracts into two separate classes and then you'd have two separate services, separate WSDL's and all.

万劫不复 2024-10-02 16:50:49

马克是完全正确的。我只是补充一下为什么 WCF 中会发生这种情况。在 WCF 中,所有与元数据相关的功能都基于服务元数据行为和 mex 端点。这两个功能都是在服务级别上定义的。因此,您不能采用更高的粒度(除非您编写大量自定义代码)并为每个端点指定元数据。

WCF 服务(类)直接映射到 wsdl:service 元素,该元素将每个协定公开为单独的 wsdl:port(在 WCF 中称为端点)。这是回答你问题的重点。如果您不希望在该 wsdl:service 中使用第二个合同,则无法在同一个类中实现它。

您提到您的服务合同共享资源。在这种情况下,您的 WCF 服务可能还包含业务逻辑。这就是你出现问题的原因。实现 WCF 服务的良好设计是将它们仅创建为单独业务逻辑类的包装器。

Marc is absolutelly right. I'm just adding why this happens in WCF. In WCF all metadata related functionality are based around service metadata behavior and mex endpoint. Both these features are defined on service level. So you can't take higher granuality (unless you write a lot of custom code) and specify metadata per endpoint.

WCF service (class) is directly mapped to wsdl:service element which exposes each contract as separate wsdl:port (in WCF known as endpoint). This is the main point in answering your question. If you don't want your second contract in that wsdl:service you can't implement it in the same class.

You have mentioned that your service contracts share resources. In that case your WCF service probably also contains business logic. That is a reason for your problems. The good design for implementing WCF services is to create them only as wrappers around separate business logic classes.

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