什么是 WCF 代理以及它们有什么用处?

发布于 2024-11-14 17:09:33 字数 183 浏览 4 评论 0原文

我最近一直在自学 WCF,甚至使用 WCF 编写了一些生产服务。但直到最近我才真正深入研究过 WCF。

我知道“代理”设计模式的想法。我还知道 ASMX Web 服务中代理的使用。但我很难理解 WCF 代理是什么以及它是如何使用的。我已经彻底阅读了有关 WCF 的 MSDN 文档,但我仍然没有掌握在 WCF 服务中使用代理的总体情况。

I have recently been educating myself about WCF and I have even written some production services using WCF. But I have never really looked too much into WCF until recently.

I am aware of the idea of the "proxy" design pattern. I am also aware of the use of a proxy with ASMX web services. But I am having a hard time understanding what a WCF proxy is and how it is used. I have looked thoroughly over the MSDN documentation about WCF, but I am still not grasping the big picture of the use of proxies with WCF services.

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

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

发布评论

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

评论(4

活雷疯 2024-11-21 17:09:33

代理是进程外服务的进程内代表。您调用代理(这很容易),它设置通信通道等并与远程服务对话(这很困难)。

另请参阅http://msdn.microsoft.com/en-us/library/ms730144 .aspx

A proxy is an in-process representative of an out-of-process service. You call the proxy (which is easy), which setups up the communication channels etc. and talks to the remote service (which is hard).

See also http://msdn.microsoft.com/en-us/library/ms730144.aspx.

掩于岁月 2024-11-21 17:09:33

WCF 代理实际上只是一个抽象级别。您可以针对代理(最终是一个作为服务契约的接口)进行编码,而无需处理处理 WCF 通信逻辑的细粒度细节。 WCF 的好处是您可以通过同一代理使用多种类型的服务通信(http、wshttp、msmq、命名管道等)。

A WCF proxy is really just a level of abstraction. You code against the proxy (ultimately an interface which is a service contract) without needing to work with the fine grain detail of dealing with the WCF communication logic. The benefit of WCF is that you can use many types of communication with the service (http, wshttp, msmq, named pipes etc) with the same proxy.

哭泣的笑容 2024-11-21 17:09:33

从技术上讲,代理是公开单个 CLR 接口的 CLR 类,该接口代表
服务契约。代理提供与 ServiceContract 相同的操作,但还提供用于管理代理生命周期的附加方法,以及与服务的连接代理

                           or

用于从客户端表示服务器中的 ServiceContract 接口。通过使用代理,我们可以调用服务方法存在于服务器中的接口中。

Technically speaking Proxy is CLR Class that exposes single CLR Interface which represents the
Service Contract.The proxy provides same operations as ServiceContract , but also additional methods for managing the proxy life cycle and the connection to the service

                           or

Proxy is use to Represent the ServiceContract Interface in Server from client side.By using proxy we can invoke service methods which Present in Interface which lies in Server.

小红帽 2024-11-21 17:09:33

需要客户端代理才能使用来自 .NET 客户端的 WCF 服务。
代理是客户端内存中的一个对象,它公开与 WCF 服务相同的接口或 API。您的使用代码将针对该代理进行调用,而代理会将这些调用作为 SOAP 消息分派到 WCF 服务。

代理可以由 Visual Studio 根据 WCF 服务在 WSDL 或 WS-MetaDataExchange 端点(基于 SOAP)中公开的元数据来生成代码。

如果您想更好地控制服务消耗,那么您可以手动编写代理代码。就像您想要封装重复的使用模式,例如设置凭据等。

Client proxy is required to consume WCF services from .NET clients.
Proxy is an object in memory on the client-side that exposes the same Interface or API that the WCF service does. Your consuming code will make calls against that proxy and proxy will dispatch those calls as SOAP Messages to the WCF service.

Proxies can be code-generated by Visual Studio based on the metadata exposed by the WCF service either in WSDL or WS-MetaDataExchange endpoint(which is SOAP based).

If you want more control over service consumption then you can hand-code proxies. Like you want to encapsulate the repeating pattern of usages e.g setting up credentials etc.

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