tags:

views:

7215

answers:

6

What is the difference between web reference and service reference in WCF? Which is preferable in WCF?

+4  A: 

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.

DavidWhitney
Add Service Reference -> Advanced -> Add Web Reference... nothing like unintuitive solutions.
Jagd
+3  A: 

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

Brian Genisio
+2  A: 

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).

Wagner Silveira
+13  A: 

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.

Kevin Hoffman
+1 for adding that any standard web service with a properly formatted WSDL meets the criteria
masenkablast
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...
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.
boomhauer
+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
A: 

Add Web Reference is a wrapper over wsdl.exe and can be used to create proxies for .NET 1.1 or 2.0 clients. Of course this means when you are pointing to a WCF service you have to be pointing to an endpoint that uses basicHttpBinding (as I was).

Add Service Reference is a wrapper over svcutil.exe and also creates clients proxies (and additionally web.config entries). These proxies, however, can only be consumed by .NET 3.0+ clients.

Thanks for not plagiarizing other websites (http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx).Can't minus this just yet...
md1337
+5  A: 

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 (WSDL). Internally, it uses the ASMX communication stack on the client 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 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.

Christian Hayter