5

我只是想掌握使用 WCF,如果有人能告诉我我是否对端点有正确的想法,我正在徘徊。

我一直在浏览msdn上的视频,现在我正在徘徊配置WCF服务的方式。场景是如果我有多个 IService,例如,我有一个 IThis 和 IThat,并且客户端需要访问两者(注意:他们将使用 net.tcp),

  • IThis 处理数据库查询,并且,

  • IThat 处理独立于数据库的计算,

我假设我必须为 IThis 和 IThat 定义单独的端点,它们在客户端中分别引用。还是我会创建一个在客户端中引用并包含两者功能的整体 IThisAndThat 服务?

或者是使用多个 IService 开发和处理 WCF 服务的其他方法吗?虽然我在问你可以为 tcp 定义基地址还是只为 http 定义基地址?

~谢谢大家,任何帮助或指点都会很棒。

4

2 回答 2

4

我假设我必须为 IThis 和 IThat 定义单独的端点,它们在客户端中分别引用。还是我会创建一个在客户端中引用并包含两者功能的整体 IThisAndThat 服务?

您可以同时执行以下操作:

  • 您可以创建一个单独的服务实现类 - 一个用于IThis,另一个用于IThat
  • 或者您可以创建一个服务实现类来实现IThisIThat

这个选择完全取决于你。

对于您拥有的每个服务实现类,您可以定义您希望拥有的任意数量的端点。因此,如果你有一个ThisServiceimplementation IThis,你可以为它定义一个 HTTP 和一个 TCP 端点,你也有一个为它定义 TCP 端点的ThatService实现IThat。这完全取决于你。

但是:您只能为每个服务实现类定义端点 - 如果您ThisAndThatService同时实现两个服务合同,则不能定义 3 个端点IThis和两个不同的IThat端点 - 您定义的端点是每个服务实现类。

虽然我在问你可以为 tcp 定义基地址还是只为 http 定义基地址?

是的,绝对 - 您可以为各种寻址方案(http、net.tcp、net.msmq、net.pipe 等)中的每一种定义一个基地址。

于 2011-05-30T04:50:48.820 回答
1

Some basics:

Each service has one or more endpoints. The endpoints are specific to their relevant service, i.e. each endpoint can only belong to one service and cannot be shared between services.

An endpoint defines an entrypoint to the service - it includes an address, binding and contract that can be utilized by a client.

Different endpoints must have different addresses, and can have different bindings and contracts (i.e. they do not have to). Typically, different endpoints have different bindings - that is, transport protocol. They can have different contracts if particular clients are only supposed to have access to certain operations.

Finally, your service must implement all of the contracts that its various endpoints expose.

Here's a very concise and straightforward MSDN page which describes these concepts. http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9f4391e9-8b9f-4181-a081-860d42b992a9/

There's a lot of information on WCF on the web, and there's a lot to learn. Best to look at some tutorials or guides which focus on what you are trying to do.

于 2011-05-30T04:24:05.050 回答