WCF:为什么合同是在端点上而不是在服务上? [英] WCF: Why is Contract on Endpoint and not on Service?

查看:21
本文介绍了WCF:为什么合同是在端点上而不是在服务上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图真正获得"端点合同:

Trying to really 'get' endpoint contracts:

我理解提供不同的端点来支持不同的绑定,但是什么时候可以为一项服务定义 n 个端点,并使用不同的契约?似乎在大多数情况下(bar IMetadataExchange)无论协议如何,端点合同都是相同的,不是吗?

I understand offering different endpoints to support different bindings, but when would one define n endpoints for a service, and use different contracts? Seems that in most cases (bar IMetadataExchange) the endpoint contract would be the same no matter the protocol, no?

如果大多数情况下所有端点的合同都相同,那么在父服务而不是每个端点上定义服务合同是否过于简单(为什么?)(看起来很麻烦/重复),同时允许在需要时覆盖端点(例如:IMetadataExchange).

If most of the time the contract would be the same across all endpoints, would it have been too simplistic (and why?) to define the service contract on the parent service instead of on each endpoint (seems cumbersome/repetitive), while alllowing an override on the endpoint for when needed (eg: IMetadataExchange).

感谢帮助我解决那些让我彻夜难眠的小问题;-)

Thanks for help with the small questions that keep me up at night ;-)

推荐答案

好吧 - 您在 标签中定义的 service 是实际的实现代码 - 构成服务的实际 C# 或 VB.NET 代码行.因此,它是一个具体类(它甚至可能实现多个服务合同).这只是服务器端.

OK, well - the service that you define in the <service> tag is the actual implementation code - the actual C# or VB.NET lines that make up the service. Therefore, it's a concrete class (which might even implement multiple service contracts). This is server-side only.

端点是服务器和客户端之间的通信渠道,在这两者之间,您希望共享合同 - 从不强>该合同的任何具体实施.端点只会用于单个服务合同 - 如果您的具体服务实现了多个合同,则您需要向客户端公开多个端点以提供所有这些功能.

The endpoint however is the communications channel between the server and the client, and between those two, you want to share only the contract - never any concrete implementation of that contract. The endpoint will only ever be used for a single service contract - if your concrete service implements multiple contracts, you need to expose multiple endpoints to the clients to provide all that functionality.

这是否让事情变得更清楚一点?

Does that make things a bit clearer?

这篇关于WCF:为什么合同是在端点上而不是在服务上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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