WCF 多端点和 IServices
我只是想掌握使用 WCF,并且我想知道是否有人可以告诉我我对端点的想法是否正确。
我一直在浏览msdn上的视频,现在我正在思考如何配置WCF服务。情况是,如果我有多个 IService,例如,我有一个 IThis 和 IThat,并且客户端需要访问这两个服务(注意:他们将使用 net.tcp),
IThis 处理数据库查询,
IThat 处理独立于数据库的计算,
我假设我必须为 IThis 和 IThat 定义单独的端点,它们在客户单独。或者我会创建一个在客户端中引用的整体 IThisAndThat 服务并包含两者的功能吗?
或者是使用多个 IService 开发和处理 WCF 服务的其他方法吗?当我问你能否定义 tcp 或仅 http 的基地址?
~谢谢大家,任何帮助或指点都会很棒。
I am just trying to get to grips with using WCF, and I am wandering if someone could tell me if I have the right idea with endpoints.
I have been working through the videos on msdn, and now I am wandering about the way to configure WCF Service. The scenario is if I have multiple IServices, e.g. such that I have an IThis and IThat, and the client needs the access both (note: they will be using net.tcp),
IThis handles database querying and,
IThat handles calculations independent of the database,
I assume that I have to define separate Endpoints for IThis and IThat, that are referenced in the client separately. Or would I create an overall IThisAndThat Service that gets referenced in the client and contains the functionality for both??
Or is are the other ways for developing and handling WCF Services with multiple IServices? While I'm asking can you define base address for tcp or only http?
~Thanks all, any help or pointers would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以同时执行这两项操作:
IThis
,另一个用于IThat
IThis
和IThat
的服务实现类。这种选择完全取决于您。
对于您拥有的每个服务实现类,您可以定义您希望拥有的任意数量的端点。因此,如果您有一个实现
IThis
的ThisService
,您可以为其定义一个 HTTP 和一个 TCP 端点,并且您还有一个实现ThatService
IThat
您为其定义 TCP 端点。这完全取决于你。但是:您只能为每个服务实现类定义端点 - 如果您有一个实现两个服务契约的
ThisAndThatService
,则无法定义 3 个端点对于IThis
和两个不同的IThat
- 您定义的端点是针对每个服务实现类的。是的,绝对的 - 您可以为每个不同的寻址方案(http、net.tcp、net.msmq、net.pipe 等)定义基地址。
You can do both:
IThis
, another one forIThat
IThis
andIThat
That choice is entirely up to you.
For every service implementation class that you have, you can define any number of endpoints you wish to have. So if you have an
ThisService
implementingIThis
, you can define a HTTP and a TCP endpoint for that, and you also have aThatService
that implementsIThat
for which you define a TCP endpoint. That's totally up to you.BUT: you can only define your endpoints for each service implementation class - if you have a
ThisAndThatService
implementing both service contracts, you cannot define 3 endpoints forIThis
and two different ones forIThat
- the endpoints you define are per service implementation class.Yes, absolutely - you can define a base address for each of the various addressing schemes (http, net.tcp, net.msmq, net.pipe and so forth).
一些基础知识:
每项服务都有一个或多个端点。端点特定于其相关服务,即每个端点只能属于一个服务并且不能在服务之间共享。
端点定义了服务的入口点——它包括客户端可以使用的地址、绑定和契约。
不同的端点必须具有不同的地址,并且可以具有不同的绑定和契约(即它们不必)。通常,不同的端点具有不同的绑定——即传输协议。如果特定客户只能访问某些操作,他们可以签订不同的合同。
最后,您的服务必须实现其各个端点公开的所有契约。
这是一个非常简洁明了的 MSDN 页面,它描述了这些概念。 http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9f4391e9-8b9f-4181-a081-860d42b992a9/
有很多关于 WCF 的信息网络,还有很多东西要学。最好看一些专注于您想要做的事情的教程或指南。
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.