What are WCF Proxies and what are they good for?

2019-02-03 15:13发布

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.

4条回答
ら.Afraid
2楼-- · 2019-02-03 15:30

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.

查看更多
做自己的国王
3楼-- · 2019-02-03 15:30

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.

查看更多
ら.Afraid
4楼-- · 2019-02-03 15:46

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.

查看更多
相关推荐>>
5楼-- · 2019-02-03 15:54

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.

查看更多
登录 后发表回答