What is the difference between web reference and service reference in WCF? Which is preferable in WCF?
-
Also take a look at Channel Factories - http://stackoverflow.com/questions/1698275/wcf-channelfactory-vs-generating-proxy – Manish Jain Mar 06 '13 at 22:26
-
1hmm, perhaps select an answer? good question by the way – Daniël Tulp Jul 16 '14 at 13:11
5 Answers
The low-level answer here is that a Web Reference will create a client proxy class that allows your code to talk to a Web Service that is described via WSDL and communicates via SOAP or HTTP GET (other posters indicate that it is only ASMX, but Web References can also talk to Java-based Web Services or Python-based or Ruby so long as they all talk WSDL and conform to the WS-I interoperability standard).
A Service Reference will create a client proxy class that communicates with a WCF-based service : regardless of whether that WCF service is a Web Service or not.

- 5,154
- 4
- 31
- 33
-
1+1 for adding that any standard web service with a properly formatted WSDL meets the criteria – sidney.andrews Mar 04 '10 at 12:51
-
So can I add a service reference to a java based web service? Would Would it still make sense? since Java knows nothing about the wcf stack... – user20358 Sep 21 '10 at 11:59
-
yes, you can add a service reference to a java etc web service, if it has a wsdl. The service reference will treat it like a "classic" web reference in this case. – Brady Moritz Oct 09 '10 at 19:45
-
+1 for stating that Web Service can consume WSDL-described web services, as well as ASMX. As a matter of fact, I have a business layer that has a web reference and a service reference. The web reference consumes a WSDL web service, while the service reference consumes an ASMX service. – Jagd Oct 25 '10 at 16:49
A Web Reference allows you to communicate with any service based on any technology that implements the WS-I Basic Profile 1.1, and exposes the relevant metadata as WSDL. Internally, it uses the ASMX communication stack on the client's side.
A Service Reference allows you to communicate with any service based on any technology that implements any of the many protocols supported by WCF (including but not limited to WS-I Basic Profile). Internally, it uses the WCF communication stack on the client side.
Note that both these definitions are quite wide, and both include services not written in .NET.
It is perfectly possible (though not recommended) to add a Web Reference that points to a WCF service, as long as the WCF endpoint uses basicHttpBinding
or some compatible custom variant.
It is also possible to add a Service Reference that points to an ASMX service. When writing new code, you should always use a Service Reference simply because it is more flexible and future-proof.

- 1
- 1

- 30,581
- 6
- 72
- 99
-
2Can anyone get me started on how to consume a service via Service Reference? With Web Reference, I always seem to be able to find the core functions in some kind of service object. With a Service Reference, not so much. As an example, I'm trying to use the FedEx rates service to get prices for the various FedEx shipping options. I know there's a getRates() call in there somewhere, but I can't find it with a Service Reference. – Ben Mills Jan 20 '16 at 20:16
-
The service reference is the newer interface for adding references to all manner of WCF services (they may not be web services) whereas Web reference is specifically concerned with ASMX web references.
You can access web references via the advanced options in add service reference (if I recall correctly).
I'd use service reference because as I understand it, it's the newer mechanism of the two.

- 4,290
- 4
- 24
- 30
-
8Add Service Reference -> Advanced -> Add Web Reference... nothing like unintuitive solutions. – Jagd Oct 25 '10 at 16:53
Service references deal with endpoints and bindings, which are completely configurable. They let you point your client proxy to a WCF via any transport protocol (HTTP, TCP, Shared Memory, etc)
They are designed to work with WCF.
If you use a WebProxy, you are pretty much binding yourself to using WCF over HTTP

- 47,787
- 16
- 124
- 167
Another point to take in consideration is that the new UI for Service Interface will give you much more flexibility on how you want to create your proxy class. For example, it will allow you to map data contracts to existing dlls, if they match (actually this is the default behaviour).

- 1,576
- 11
- 9