WCF - channel factory vs client base

后端 未结 1 1227
遥遥无期
遥遥无期 2020-12-29 05:05

I am new to WCF. Initially I created a WCF service and used the generated client proxy to consume the service from client. So whenever I performed some operations on service

相关标签:
1条回答
  • 2020-12-29 05:39

    There's a difference using async between ClientBase and ChannelFactory<T>. Basically ClientBase uses the event-driven asynchronous model.

    I used ChannelFactory<T> extensively in an application I developed at work, mainly because the contracts were available in a common library for the application and I don't like using the Add Service Reference. I cache each unique instance of the ChannelFactory upon creation, and then when I need to call an operation I'll open a communication channel from that instance, make my call, and close the communication channel.

    Most of the startup cost for WCF is in creation of the client, and this way you only pay it once for the life of the application - creating communication channels is trivial.

    For more info on the async for ClientBase and ChannelFactory<T>, see:

    How to: Call WCF Service Operations Asynchronously

    How to: Call Operations Asynchronously Using a Channel Factory

    0 讨论(0)
提交回复
热议问题