What are WCF Proxies and what are they good for?

一世执手 提交于 2019-11-30 12:57:14

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/6285939/what-are-wcf-proxies-and-what-are-they-good-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!