Building proxy with ChannelFactory vs svcutil ??dear all,<br/><br/>I have a simple question that i wonder the reason of it.<br/>I have seen in many sample and forums sample code that people most of the time use the ChannelFactory class to create the proxy and some others use service reference in project while others use the tool svcutil to generate the proxy class.<br/><br/>Is there any real different by generating the proxy through ChannelFactory or is it a matter of taste ?<br/><br/>thnaks for help<br/>serge<hr class="sig">Your experience is build from the one of others© 2009 Microsoft Corporation. All rights reserved.Wed, 08 Jul 2009 11:48:28 Za4a392cc-a6c0-4f05-a5e7-306a9c4d4130http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#a4a392cc-a6c0-4f05-a5e7-306a9c4d4130http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#a4a392cc-a6c0-4f05-a5e7-306a9c4d4130Serge Calderarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Serge%20CalderaraBuilding proxy with ChannelFactory vs svcutil ??dear all,<br/><br/>I have a simple question that i wonder the reason of it.<br/>I have seen in many sample and forums sample code that people most of the time use the ChannelFactory class to create the proxy and some others use service reference in project while others use the tool svcutil to generate the proxy class.<br/><br/>Is there any real different by generating the proxy through ChannelFactory or is it a matter of taste ?<br/><br/>thnaks for help<br/>serge<hr class="sig">Your experience is build from the one of othersFri, 03 Jul 2009 08:03:59 Z2009-07-03T08:03:59Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#81211bf2-81df-4b92-8268-ddf72b7e95cfhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#81211bf2-81df-4b92-8268-ddf72b7e95cfAlex80http://social.msdn.microsoft.com/Profile/en-US/?user=Alex80Building proxy with ChannelFactory vs svcutil ??A client created through a service reference is something like a &quot;ready to go&quot;, &quot;out of the box&quot; solution. It's extremely easy to use and simplifies getting started with WCF.<br/> <br/> Svcutil is simply the command-line version of &quot;Add service reference&quot;.<br/> <br/> Using a ChannelFactory is slightly more effort e.g. to instantiate one you have to specifiy its configuration manually. Under the hood, a client created through the service reference does all that stuff for you. A Channelfactory, however, is more flexible and efficent. I personally only use ChannelFactories because they allow me to inject them into a component for unit testing (with some wrappers). Furthermore, creating a ChannelFactory is quite expensive. Because of that a client caches those factories. As for me I prefer to control the lifecycle of the factory explicitly. It makes me more aware about when/how the factories are created. In order to use a ChannelFactory, you would still add a service reference (or through svcutil).<br/> <br/> Hth,<br/> Alex<br/> <br/><hr class="sig">AlexFri, 03 Jul 2009 18:33:12 Z2009-07-03T18:33:12Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#f404ecf7-e087-4a28-ac12-724b44c0cefehttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#f404ecf7-e087-4a28-ac12-724b44c0cefeNordine Ben Bachirhttp://social.msdn.microsoft.com/Profile/en-US/?user=Nordine%20Ben%20BachirBuilding proxy with ChannelFactory vs svcutil ??Use the channelfactory to share your datacontracts between the server and the client when you are writting both the client and the server. I personally use the channelfactory as often as possible, specially during development, when you don't want to constantly regenerate proxy classes.<hr class="sig">Nordine Ben BachirFri, 03 Jul 2009 21:30:47 Z2009-07-03T21:30:47Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#e038903a-9330-44ee-92fc-790089d20ed6http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#e038903a-9330-44ee-92fc-790089d20ed6Serge Calderarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Serge%20CalderaraBuilding proxy with ChannelFactory vs svcutil ??Thnaks for your comment;<br/>At the end performance is the same for both approach ?<hr class="sig">Your experience is build from the one of othersFri, 03 Jul 2009 22:51:35 Z2009-07-03T22:51:35Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#ba6d30e1-05b7-49be-b670-ae5d0f59b1a3http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#ba6d30e1-05b7-49be-b670-ae5d0f59b1a3Serge Calderarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Serge%20CalderaraBuilding proxy with ChannelFactory vs svcutil ??&quot;Using a ChannelFactory is slightly more effort e.g. to instantiate one you have to specifiy its configuration manually&quot;<br/>What do you mean that you need to configure it manually ?<br/>Do you means that you are not using either  a config file for you channel setting and endpoint and you define all those settings through code ?<hr class="sig">Your experience is build from the one of othersFri, 03 Jul 2009 22:53:41 Z2009-07-03T22:53:41Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#f3eaf504-7fbc-4102-8282-3e86361a592chttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a4a392cc-a6c0-4f05-a5e7-306a9c4d4130#f3eaf504-7fbc-4102-8282-3e86361a592cAlex80http://social.msdn.microsoft.com/Profile/en-US/?user=Alex80Building proxy with ChannelFactory vs svcutil ??From MSDN &quot;How to use a ChannelFactory&quot; http://msdn.microsoft.com/en-us/library/ms734681.aspx.<br/> <br/> To get started with a ChannelFactory you need to:<br/> <br/> <pre class=libCScode style="white-space:pre-wrap"> BasicHttpBinding myBinding = <span style="color:blue">new</span> BasicHttpBinding();<br/> <br/> EndpointAddress myEndpoint = <br/> <span style="color:blue">new</span> EndpointAddress(<span style="color:maroon"><span style="color:maroon">&quot;http://localhost/MathService/Ep1&quot;</span> </span> );<br/> <br/> ChannelFactory&lt;IMath&gt; myChannelFactory =<br/> <span style="color:blue">new</span> ChannelFactory&lt;IMath&gt;(myBinding, myEndpoint);<br/> <br/> <span style="color:green">// Create a channel.</span> <br/> IMath wcfClient1 = myChannelFactory.CreateChannel();<br/> </pre> I believe the example given in MSDN is even a bit too complicated. Just passing the endpoint config name should be enough. So ultimately it's not a big difference. Just remember that you have to manage proper caching/reuse of the ChannelFactory yourself. Do not recreate the ChannelFactory everytime you create a channel!<br/> <br/> With a client it would be just a single object you have to create. Nothing else to worry about.<br/> <br/> MyService svc = new MyService();<br/> <br/> svc.MyOperation();<br/> <br/><hr class="sig">AlexSat, 04 Jul 2009 11:08:16 Z2009-07-04T11:08:16Z