Web Service vs WCF Service - wcf

What is the difference between them?
When would I opt for one over the other?

This answer is based on an article that no longer exists:
Summary of article:
"Basically, WCF is a service layer that allows you to build applications that can communicate using a variety of communication mechanisms. With it, you can communicate using Peer to Peer, Named Pipes, Web Services and so on.
You can’t compare them because WCF is a framework for building interoperable applications. If you like, you can think of it as a SOA enabler. What does this mean?
Well, WCF conforms to something known as ABC, where A is the address of the service that you want to communicate with, B stands for the binding and C stands for the contract. This is important because it is possible to change the binding without necessarily changing the code. The contract is much more powerful because it forces the separation of the contract from the implementation. This means that the contract is defined in an interface, and there is a concrete implementation which is bound to by the consumer using the same idea of the contract. The datamodel is abstracted out."
... later ...
"should use WCF when we need to communicate with other communication technologies (e,.g. Peer to Peer, Named Pipes) rather than Web Service"

From What's the Difference between WCF and Web Services?
WCF is a replacement for all earlier web service technologies from Microsoft. It also does a lot more than what is traditionally considered as "web services".
WCF "web services" are part of a much broader spectrum of remote communication enabled through WCF. You will get a much higher degree of flexibility and portability doing things in WCF than through traditional ASMX because WCF is designed, from the ground up, to summarize all of the different distributed programming infrastructures offered by Microsoft. An endpoint in WCF can be communicated with just as easily over SOAP/XML as it can over TCP/binary and to change this medium is simply a configuration file mod. In theory, this reduces the amount of new code needed when porting or changing business needs, targets, etc.
ASMX is older than WCF, and anything ASMX can do so can WCF (and more). Basically you can see WCF as trying to logically group together all the different ways of getting two apps to communicate in the world of Microsoft; ASMX was just one of these many ways and so is now grouped under the WCF umbrella of capabilities.
Web Services can be accessed only over HTTP & it works in stateless environment, where WCF is flexible because its services can be hosted in different types of applications. Common scenarios for hosting WCF services are IIS,WAS, Self-hosting, Managed Windows Service.
The major difference is that Web Services Use XmlSerializer. But WCF Uses DataContractSerializer which is better in performance as compared to XmlSerializer.

Web Service
is based on SOAP and return data in XML form.
It support only HTTP protocol.
It is not open source but can be consumed by any client that understands xml.
It can be hosted only on IIS.
WCF
is also based on SOAP and return data in XML form.
It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
The main issue with WCF is, its tedious and extensive configuration.
It is not open source but can be consumed by any client that understands xml.
It can be hosted with in the applicaion or on IIS or using window service.

Basic and primary difference is, ASP.NET web service is designed to exchange SOAP messages over HTTP only while WCF Service can exchange message using any format (SOAP is default) over any transport protocol i.e. HTTP, TCP, MSMQ or NamedPipes etc.

What is the difference between web service and WCF?
Web service use only HTTP protocol while transferring data from one application to other application.
But WCF supports more protocols for transporting messages than ASP.NET Web services. WCF supports sending messages by using HTTP, as well as the Transmission Control Protocol (TCP), named pipes, and Microsoft Message Queuing (MSMQ).
To develop a service in Web Service, we will write the following code
[WebService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string Test(string strMsg)
{
return strMsg;
}
}
To develop a service in WCF, we will write the following code
[ServiceContract]
public interface ITest
{
[OperationContract]
string ShowMessage(string strMsg);
}
public class Service : ITest
{
public string ShowMessage(string strMsg)
{
return strMsg;
}
}
Web Service is not architecturally more robust. But WCF is architecturally
more robust and promotes best practices.
Web Services use XmlSerializer but WCF uses DataContractSerializer. Which is
better in performance as compared to XmlSerializer?
For internal (behind firewall) service-to-service calls we use the net:tcp
binding, which is much faster than SOAP.
WCF is 25%—50% faster than ASP.NET Web Services, and approximately 25%
faster than .NET Remoting.
When would I opt for one over the other?
WCF is used to communicate between other applications which has been developed on other platforms and using other Technology.
For example, if I have to transfer data from .net platform to other application which is running on other OS (like Unix or Linux) and they are using other transfer protocol (like WAS, or TCP) Then it is only possible to transfer data using WCF.
Here is no restriction of platform, transfer protocol of application while transferring the data between one application to other application.
Security is very high as compare to web service

The major difference is time-out, WCF Service has timed-out when there is no response, but web-service does not have this property.

Related

what is WCF and how does it work?

what is this WCF ? i used web services little bit but don't know about theses WCF, read a lot on google but couldn't get its technical terms like
http://www.codeproject.com/Articles/139787/What-s-the-Difference-between-WCF-and-Web-Services
or msdn.
It says like communication over HTTP and SOAP , serialization, soap etc but yet I'm not qualified to understand these. Help me, guide me and please in easy wordings.
[WebService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string Test(string strMsg)
{
return strMsg;
}
}
etc
and how to use them with asp.net ?
Windows communication foundation or Wcf is a framework for building services. Wcf supports exposing web services, services based on urls (rest) or services ment only to work on a single machine, such as two different programs communicating via shared memory.
Basically wcf abstracts the service (a .net interface) and the transport (or in wcf terms, a binding). A single service in Wcf can be exposed as a web service or using shared memory without any actual code changes, the endpoints are all based on app config files.
Perhaps this article on msdn will make things clearer
http://msdn.microsoft.com/en-us/library/ms731082.aspx
Some terms,
Interoperability - to operate, or work together, with something else (inter- between, operate- work together) a wcf service can interoperate with a client written in java for example
Serialization - to convert an object to a stream of bytes that can be sent somewhere and then deserialized back into an object

What is the relationship between WCF, Rest and SOAP?

What is the relationship between WCF and REST&SOAP? Is WCF based on one of those technologies (REST or SOAP) or it is a separate technology?
WCF is a messaging framework for building distributed systems. Distributed systems is mostly just another word for web services.
What this means is that you can write methods in C# (or any of the .NET languages) and then apply a bunch of configurations to the code that make your code accessible to others and turn your code into a web service.
Those "bunch of configurations" are WCF. WCF allows you to expose your methods to other computers or applications using REST if you set up the WCF configurations around your C# code to expose it as a RESTful service. Or, you can easily take the same C# methods and make them available via the SOAP protocol.
If you have a method called "GetData()", you can set up the WCF configuration to make that method available in a service that is hosted in IIS. When someone calls that service, they can send an HTTP GET request to http://www.yourdomain.com/SomeService/GetData, and the GetData method will receive the message and send back a response. When you make a GET request over HTTP, you're using the REST. REST is pretty much tied to HTTP as the transport protocol. REST also has no standard message format. Whatever you want to send in your HTTP message, and however you want to send it is OK. You can send XML, or JSON, or just plain text. You can use POST, or GET or PUT or any of the HTTP verbs as well.
With SOAP, your messages can be sent to the service using any transport protocol -- you aren't tied to HTTP. SOAP messages are designed to be transport neutral. They are encoded in XML and the XML always has a head and a body node inside of an envelope node. There are lots of web standards around SOAP -- standards for putting security, sessions and other features into the header of the message, for example. Also, with SOAP, you get a WSDL, which I won't go into explaining here, but it makes it a LOT easier for clients to program against. Most programming languages have a method of taking a WSDL and converting it into strongly-typed methods and objects so that your service is easy to call.
REST is very popular on the internet and is as scalable as the internet (i.e. VERY scalable). SOAP is very popular in business-to-business applications.
WCF isn't automatically REST or SOAP, but you can make it that way. What you need here is a tutorial:
WCF
http://www.codeproject.com/Articles/406096/A-beginners-tutorial-for-understanding-Windows
REST
http://rest.elkstein.org/
Here's some other interesting stuff:
WCF - REST / SOAP
https://msdn.microsoft.com/en-us/library/hh323708(v=vs.100).aspx
WCF and REST
https://msdn.microsoft.com/en-us/library/ee391967.aspx
Or you can do a google/bing/metacrawler/altavista search on your own.....
From MSDN
The WCF programming model provides various capabilities, such as SOAP
services, web HTTP services, data services, rich internet application
(RIA) services, and workflow services. SOAP services support
interoperability between systems that are built with Java, other
platforms, and those that use messaging standards that are supported
by Microsoft®. SOAP services also support transports such as HTTP,
TCP, named pipes, and MSMQ. Web HTTP services and data services both
support REST. Web HTTP services enable you to control the service
location, request and response, formats, and protocols. Data services
enable you to expose data models, and data-driven logic as services.
WCF also includes two programming models: The service model and the
channel model. The service model provides a framework for defining
data contracts, service contracts and service behaviors. The channel
model supports specifying formats, transports, and protocols.
Both SOAP and REST services can provide functionality to web
applications, and both can be used to exchange information in the
web's distributed environment. Each one has its own advantages, and
limitations.
Although, this question has got several good answers, just putting in my 2-cents, in an attempt for newbies to WCF vs SOAP vs REST-full services, to make it a bit easier for them to understand.
We get confusions, whether WCF supports both REST and SOAP ? And, normally, we just see generic definitions about SOAP and REST. So , we need something from Microsoft to make us feel the truth : ) So here's a screenshot from Microsoft MSDN :
So, yes, WCF supports both .
In context with OP:
SOAP services: in WCF programming model support interoperability between systems that are built with Java, other
platforms, and those that use messaging standards that are supported
by Microsoft®. These also support transports such as HTTP,
TCP, named pipes, and MSMQ.
Web HTTP services : in WCF programming model supports REST. [Source: MSDN]

I'm learning WCF and I'm stumped; why would I use this over a regular web service?

What benefits does WCF bring to the table and why should I use this new technology over good old ASP.Net web services?
Maybe you don't need to transition to WCF if regular Web-Service will work for you,
however WCF encompasses more than just Web-Services.
With WCF you can utilize different communication channels (such as Web-Services, MSMQ, named pipes...) utilizing the same end-point service handler code.
WCF also has different built-in security mechanisms, allows you to utilize different serialization mechanisms (if something other than Soap is needed like raw JSON), hosting of services without the requirement of needing a web project etc...
As such WCF is more a general service hosting framework that can replace regular ASMX web services
Here is a good article from msdn that talks about the differences between ASMX and WCF
A few key areas
Serialization - Asmx uses XmlSerializer while WCF uses the DataContractSerializer. The Datacontract serializer is about 10% faster (source along with other information)
Differences Between ASMX and WCF Services
Greater protocol support (HTTP, TCP, ICP, MSMQ for WCF), ASMX only supports HTTP

Questions on WCF

I am learning WCF,one of the benefits of WCF is that you can use WCF even the client and service are not in the same network.Can anyone explain why?
Why using normal asp.net services, .NET remoting or Windows enterprise service client and service have to be in the same network?
Another question is that does the client needs to have a service contract interface and data contract? I assume not ,but how the client understand the type returned from the WCF services?
Edit: Reflecting More comments
A primer on WCF (such as What Is Windows Communication Foundation?) is a good place to start. WCF can use SOAP to implement the contracts way down deep. WCF also uses a variety of communication facilities within windows (and any custom ones you want to create) so talking across machines is built in.
The very essence of contract (IMO) implies that this is present on both sides of the communication. In a pure .net cases I've usually put the contract definitions in separate assemblies and share them. In other places I've used WSDL to be the main contract definition so that the client and service share definitions.
Edit: Answering comments
You can knock up simple examples of communication in WCF easilyy (provided you know the basics of comms on windows including firewalls etc). However doing something custom is not easy but there are many many resources on the web and books to help you get there.
The books i used:
http://www.amazon.com/Programming-WCF-Services-Juval-Lowy/dp/0596526997
http://www.amazon.com/Essential-Windows-Communication-Foundation-WCF/dp/0321440064/ref=pd_bxgy_b_img_c
http://www.amazon.com/Inside-Windows-Communication-Foundation-Developer/dp/0735623066/ref=sr_1_1?ie=UTF8&s=books&qid=1252111759&sr=1-1
Another question on SO with a set of resources is "WCF for the Totally Clueless"
I don't know where you read that a benefit of WCF is that it allows the client and server to be on different networks. They can already be on different networks using .NET Remoting or DCOM (Enterprise Services).
The client does need to know the service contract and any other contracts required in order to use the service. This can be provided through WSDL or the Metadata Exchange Protocol (mex). If using .NET on both sides, then it is possible to share the contract assemblies, but this introduces a coupling between client and service.
Previous Microsoft technologies were designed for some specific needs in particular environment. For example ASMX Web Services were designed to send and receive messages using SOAP over Http only. .NET Remoting specific to Microsoft environment, no interoperability. But WCF is designed to send and receive messages using any format (SOAP as default) over any transport protocol i.e. HTTP, TCP, NamedPipes, MSMQ etc.
And your second question "but how the client understand the type returned from the WCF services?"
Its through proxy, client interacts with proxy which contains all the types etc.
You can find a good concepts and questions here for understanding WCF core concepts.

What are the differences between WCF and traditional ASP.NET Web

I am new to WCF and Web Services in general. What are the improvements that WCF brings to the table? Can anyone give a side-by-side example of a traditional web service and the same one written using WCF and point out the differences and advantages?
Duplicate question Moving ASP.net webservices to WCF
EDIT: Think i found the answer you where looking for a side-by-side code based comparison and even better it's from MSDN: Comparing ASP.NET Web Services to WCF Based on Development
There are several related questions:
Difference between aspnet web method and wcf webservice
Benfits of using WCF
Moving aspnet web services to wcf
However you asked for a side by side comparison in which case i think Sam's Wcf vs ASMX blog article is more what you are looking for.
Quoting ad-verbatim (let me know if i should just leave it as a link):
WCF vs. ASMX
Protocols Support
WCF
HTTP
TCP
Named pipes
MSMQ
Custom
UDP
ASMX
HTTP only
Hosting
ASMX
Can be hosted only with HttpRuntime on IIS.
WCF
A WCF component can be hosted in any kind of environment in .NET 3.0, such as a console application, Windows application, or IIS.
WCF services are known as 'services' as opposed to web services because you can host services without a web server.
Self-hosting the services gives you the flexibility to use transports other than HTTP.
WCF Backwards Compatibility
The purpose of WCF is to provide a unified programming model for distributed applications.
Backwards compatibility
WCF takes all the capabilities of the existing technology stacks while not relying upon any of them.
Applications built with these earlier technologies will continue to work unchanged on systems with WCF installed.
Existing applications are able to upgrade with WCF
New WCF transacted application will work with existing transaction application built on System.Transactions
WCF & ASMX Integration
WCF can use WS-* or HTTP bindings to communicate with ASMX pages
Limitations of ASMX:
An ASMX page doesn’t tell you how to deliver it over the transports and to use a specific type of security. This is something that WCF enhances quite significantly.
ASMX has a tight coupling with the HTTP runtime and the dependence on IIS to host it. WCF can be hosted by any Windows process that is able to host the .NET Framework 3.0.
ASMX service is instantiated on a per-call basis, while WCF gives you flexibility by providing various instancing options such as Singleton, private session, per call.
ASMX provides the way for interoperability but it does not provide or guarantee end-to-end security or reliable communication.
WCF is far wider in scope than ASP.Net webservices.
WCF can run in any application. APS.Net webservices only run in IIS.
WCF supports models like ReST, Remoting, SOAP, MSMQ etc. ASP.Net only supports SOAP
WCF is more configurable.
WCF supports a more declarative way of programming. You can get more done with less code.
ASP.NET Web Services are pretty much just that. Web Services. They're SOAP/WSDL based and provide their services only to the web.
WCF Services offer a much more flexible framework. For instance, depending on how the service is defined, it can be a Web Service hosted in IIS which serialized its data via XML and uses the REST model...or it can be a Remote Windows Service that is hosted in it's own process and serializes its data via binary. All of this is achieved using the different Service/Data contracts in WCF.
In short...you can make a WCF service look almost identical to a .NET 2.0 Web Service fairly easily but, with a little work, you can do a WHOLE LOT MORE.