tags:

views:

34

answers:

3

I have a WCF deployed on IIS. Now by adding web reference of it i am using it on my app.

So I have two questions:

  1. Is it the best method of consuming WCF.
  2. If the answer of first question is yes then what is the role of svcutil.exc, I mean what is the use of creating wcf proxy class. and if the answer is "No" then why?
+1  A: 

It is the easiest solution if you develop with visual studio and have access the remote WCF service.

If you are developing using another IDE, you might want to use SvcUtil to generate your proxies.

If you prefer to have a simple CS file containing the generated client, you might also choose to generate it using SvcUtil.

You may also completely ignore SvcUtil and the Service Reference wizard and use the ChannelFactory class to generate proxies dynamically.

Johann Blais
thanks, what is the benefit of using channel Factory class. Generate proxies dynamically what it mean?
Jeevan Bhatt
A: 

You should use "Add Service Reference" in Visual Studio (not Add Web Reference) for WCF.

It is the easiest way - since you can do it right in Visual Studio. What it does under the covers is basically call svcutil.exe (or you can do that manually, from the command line yourself), and create a service proxy class for use on the client side.

The use of svcutil.exe is many fold - you can create a client proxy class from a running service (or from an existing WSDL/XSD file), you can verify services, you can export metadata from a service for clients to consume, and a great many more options. It's the "Swiss Army Knife" of WCF tools.

WCF uses a concept that all calls to your service must go through a client proxy - this is the place where the entire WCF runtime lives, and where all the WCF extensibility points are located. This proxy converts your call to a method on the client into a serialized message that gets sent across the network to the server for processing, and it also handles "unpacking" the response from the call back into classes and objects on your client side for your use.

marc_s
thanks for your answer. Ok what i understand from you, that there is no significant difference between consuming wcf methods. Am i right ?
Jeevan Bhatt
Using "Add Service Reference" or using "svcutil.exe" basically gives you the same results, yes. Use whichever works best for you.
marc_s
A: 

Adding a service reference is the quickest and easiest way but not always the best way. If you want performance then using ChannelFactory<T> is the way to go. You should know different ways to create a client side proxy and customisations that you can do.
An excellent resource is WcfGuidanceForWpf. Don't let the WPF in it scare you as it is really an excellent guidance for general WCF as well.

Pratik