什么是WCF中的代理? [英] what is proxy in WCF?

查看:65
本文介绍了什么是WCF中的代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请告诉我什么是WCF代理?请给出相同的示例代码。





谢谢

Seema

Hi,

Please tell me what is WCF proxy? Please give sample code for same.


Thanks
Seema

推荐答案

代理类是相同对象结构的表示,它将被序列化,然后通过线路传递到端点(服务)。

如果不是代理,xml / soap(或其他一些基于服务类型的格式)将直接写入,这对用户不太友好。
A proxy class is a representation of the same object structure that will be serialized and then passed over the wire to the endpoint (the service).
If it were not for the proxy, xml / soap (or some other format based on type of service) would directly have to be written and this would not be very user friendly.


代理是一个CLR类,公开表示服务合同的单个CLR接口。代理提供与服务合同相同的操作,但还有其他方法来管理代理生命周期和与服务的连接。代理完全封装了服务的每个方面:其位置,实现技术和运行时平台以及通信传输。



通过右键单击Reference并单击Add Service Reference,可以使用Visual Studio生成代理。这将打开添加服务引用对话框,您需要在该对话框中提供服务的基本地址(或基本地址和MEX URI)以及包含代理的命名空间。



也可以使用SvcUtil.exe命令行实用程序生成代理。我们需要为SvcUtil提供HTTP-GET地址或元数据交换端点地址,并且可选地提供代理文件名。默认代理文件名是output.cs,但您也可以使用/ out开关指示其他名称。



SvcUtil http://localhost/MyService/MyService.svc /out:Proxy.cs



当我们在IIS中托管并选择端口80以外的端口(例如端口88)时,我们必须提供该端口号作为基址的一部分:



SvcUtil http:// localhost:88 / MyService / MyService.svc /out:Proxy.cs
The proxy is a CLR class that exposes a single CLR interface representing the service contract. The proxy provides the same operations as service''s contract, but also has additional methods for managing the proxy life cycle and the connection to the service. The proxy completely encapsulates every aspect of the service: its location, its implementation technology and runtime platform, and the communication transport.

The proxy can be generated using Visual Studio by right clicking Reference and clicking on Add Service Reference. This brings up the Add Service Reference dialog box, where you need to supply the base address of the service (or a base address and a MEX URI) and the namespace to contain the proxy.

Proxy can also be generated by using SvcUtil.exe command-line utility. We need to provide SvcUtil with the HTTP-GET address or the metadata exchange endpoint address and, optionally, with a proxy filename. The default proxy filename is output.cs but you can also use the /out switch to indicate a different name.

SvcUtil http://localhost/MyService/MyService.svc /out:Proxy.cs

When we are hosting in IIS and selecting a port other than port 80 (such as port 88), we must provide that port number as part of the base address:

SvcUtil http://localhost:88/MyService/MyService.svc /out:Proxy.cs


这篇关于什么是WCF中的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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