388

I am totally confused between WCF and ASMX web services. I have used a lot of web services in my earlier stage, and now there is this new thing introduced called WCF. I can still create WCF that function as a web service. I think there will be more stuff in WCF.

What are the differences between WCF and Web services? When should each one be used?

hichris123
  • 10,145
  • 15
  • 56
  • 70
shailesh
  • 5,013
  • 5
  • 23
  • 22
  • 7
    There's no way this is a recommendation question. Neither ASMX nor WCF is a product. They are two iterations of web services in the Microsoft stack. The question is what are the differences, and is it worth my while to learn the new one? This is not the same thing as "should I use Telerik controls or Infragistics. – John Saunders Nov 03 '16 at 02:15

5 Answers5

403

Keith Elder nicely compares ASMX to WCF here. Check it out.

Another comparison of ASMX and WCF can be found here - I don't 100% agree with all the points there, but it might give you an idea.

WCF is basically "ASMX on stereoids" - it can be all that ASMX could - plus a lot more!.

ASMX is:

  • easy and simple to write and configure
  • only available in IIS
  • only callable from HTTP

WCF can be:

  • hosted in IIS, a Windows Service, a Winforms application, a console app - you have total freedom
  • used with HTTP (REST and SOAP), TCP/IP, MSMQ and many more protocols

In short: WCF is here to replace ASMX fully.

Check out the WCF Developer Center on MSDN.

Update: link seems to be dead - try this: What Is Windows Communication Foundation?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 17
    With visual studio 2010 .net 4.0 WCF is just as easy to write as ASMX, there is no excuse to write ASMX anymore. WCF is way faster, more flexible, more secure. ASMX is legacy and nobody should still write it period. – Tom Stickel Jan 19 '12 at 19:15
  • 15
    "Most developers incorrectly assume that ASMX requires IIS; after all, it's the only use case they've ever seen. But the truth is that ASMX doesn't have any technical dependencies on IIS whatsoever." http://msdn.microsoft.com/en-us/magazine/cc163879.aspx – MrNick May 28 '12 at 21:37
  • 2
    @MrNick: right. No IIS, but still HTTP only, and go compare the code for hosting ASMX to the code for hosting a WCF service. – John Saunders Jul 10 '13 at 05:16
  • 2
    Unfortunately the link http://keithelder.net/2008/10/17/wcf-vs-asmx-webservices/ is broken. – Robert Mar 04 '16 at 09:42
  • 2
    @codemonkeyliketab: the response is **more than 6 years old** - lightyears in the internet age! I tried to find a replacement for the WCF Developer Center - see my update – marc_s May 12 '16 at 20:23
  • WCF is installed on client's machines where as ASMX goes with your project package. – monofal Nov 07 '17 at 13:50
  • 1
    ASMX died, WCF is dead, WebAPI REST now lives ? – Kiquenet Jul 09 '18 at 21:32
36

ASMX Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type.

Second, ASMX web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc

John Saunders
  • 160,644
  • 26
  • 247
  • 397
NET Experts
  • 1,525
  • 17
  • 35
25

This is a very old question, but I do not feel that the benefits of ASMX have been fairly portrayed. While not terribly flexible, ASMX web services are very simple to use and understand. While WCF is more flexible, it is also more complex to stand up and configure.

ASMX web services are ready to stand up and add as a webservice reference as soon as you add the file. (assuming your project builds)

For the simple development workflow of create webservice -> run webservice -> add webservice reference, an ASMX webservice has very little that can go wrong, not much that you can misconfigure, and that is it's strength.

In response to those that assert that WCF replaces ASMX, I would reply that WCF would need to add a streamlined K.I.S.S. configuration mode in order to completely replace ASMX.

Example web.config for an ASMX webservice:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings />
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>
Andrew Hoffman
  • 780
  • 6
  • 14
  • I don't think WCF needs more configuration for the work that can be done using asmx webservices , and you can as well add a reference in your client side for the WCF service , WCF is way more powerful than asmx , it can do what asmx does and it will be as simple as asmx – Coder1409 Apr 07 '15 at 12:48
  • 10
    @Coder1409 well it's certainly more configuration, because some things need to be configured. Binding, discoverability, etc. Not necessary in asmx. Service contracts, operation contracts, data contracts, data members. Not necessary in asmx. Of course these things are why wcf is superior and more powerful, but to deny that it adds complexity just isn't being honest. It's reaching to say that there are no downsides. – Andrew Hoffman Apr 07 '15 at 16:40
  • Andrew, you should try creating a simple "hello, world" WCF service in .NET 4.0 or 4.5. There is almost no configuration. Configuration was changed in 4.0 so that the default generated config file does not configure the default values, and there are default sets of values for the different bindings. So, if you create a `basicHttpBinding` service, you will find almost nothing in the config file. – John Saunders Aug 04 '15 at 19:34
  • 8
    The first (second,third...) time i created a wcf it took me ages to figure out the config required. "Why do i need to do that?" i kept asking myself. "Why bother with something so complex?". asmx just worked instantly. So saying that it's just as simple just isn't true. One day i will fully understand and change my view - until that day GRRRR!!! – tomjm Oct 30 '15 at 14:55
  • 1
    @tomjm Again, try it with a modern version of Visual Studio and .NET. Among other things, the configuration system has changed to default more settings. In particular, you'll hardly need to do more than specify the URL in order to get a simple web service, http only, with no features. – John Saunders Nov 03 '16 at 02:13
  • 1
    @tomjm Well that's good to know. Honestly it used to be so much config that it made sense to use a wcf config manager app. It could do everything! _(except work out of the box with some good default settings)_ However nowadays we think more simply concerning WEB services. Wcf is still great for advanced service, but.. probably the majority of service development is webservice development, and it's hard to beat webapi2 for webservice development imo. – Andrew Hoffman Jan 01 '17 at 01:56
  • @JohnSaunders oops meant to reply to you – Andrew Hoffman Jan 01 '17 at 02:15
11

WCF completely replaces ASMX web services. ASMX is the old way to do web services and WCF is the current way to do web services. All new SOAP web service development, on the client or the server, should be done using WCF.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 32
    The trouble is, while ASMX was a simplistic model (meaning not terribly flexible), it was a simple model (meaning easy to use and understand for the most common web service needs). WCF adds a lot of extra complexity. While MS wants to replace ASMX with WCF, there seems to be a bit of resistance to it until MS makes the most common scenarios as simple as the old [Webmethod] way. – mattmc3 Nov 16 '10 at 14:57
  • 6
    WCF is not at all complex. Create a simple "hello world" web service in both and see how much code you write in each. The answer: not much in either, and only slightly more in WCF. And, BTW, ASMX already _has_ been replaced by WCF. Done deal. – John Saunders Nov 16 '10 at 19:08
  • 60
    "WCF is not at all complex" Ha. Tell that to my way overbloated web.config. – mattmc3 Jul 11 '11 at 01:57
  • @mattmc3 use a servicehostfactory http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/14/wcf-extensibility-servicehostfactory.aspx – dbobrowski Aug 20 '12 at 16:20
  • @downvoters: still curious what the problem is with this answer. – John Saunders Aug 30 '12 at 20:20
  • 27
    (Not a downvoter, but I'll tell you why) - because "this is new and that is old" is not a significant difference that anyone should care about. We don't choose tools based solely on how old they are - the hammer is really, really old, but it's still the best tool for driving nails most of the time. So, you gave a valid answer, it's just not that helpful - like the old "you are in an airplane" joke. – Jasmine Jan 22 '13 at 23:53
  • 1
    It's not a case of old vs. new. WCF has totally replaced ASMX. ASMX is a legacy technology which is not intended by Microsoft to be used for new development. Recent big hint: check out "[This Forum Has Been Retired](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads)". – John Saunders Jan 23 '13 at 00:15
  • @Jasmine - Would you mind pointing me to a place that explains the old "you are in an airplane" joke? I try to look it up each time I stumble on this post, and the only thing I ever find is http://www.madfigs.com/parables/plane.php which I don't think is what you're referring to. – bubbleking Jul 01 '15 at 15:43
  • 1
    There's a variation here: http://alunthomasevans.blogspot.com/2007/10/old-microsoft-joke.html – Jasmine Jul 02 '15 at 19:52
  • 5
    down voted - no reference. How do you know this information? Is it opinion? Do you work for microsoft? Add a reference and i will up vote. – tomjm Oct 30 '15 at 15:14
  • First of all, Microsoft MVP for seven years, including at the time of the post. Second, I gave several references in comments, and none of this is a secret. The better question is, how is it possible that _you_ don't know this? – John Saunders Oct 30 '15 at 15:43
  • 1
    Neither a downvoter or an upvoter. The difference between asmx and wcf is the same difference between automatic transmission and manual stick shift. I can sit here an talk about all the good thing about manual transmission (which they are valid) but my wife will kill me if I buy a car that's not automatic. – Zuzlx Aug 22 '16 at 20:59
  • @zuzlx bad analogy. More like the difference between AC and DC power coming into homes. Or VHS vs. BETAMAX. – John Saunders Aug 22 '16 at 21:01
  • What if you're building a service to handle a kind of document standard that is XML, and you don't want or need any flexibility that WCF offers? Why wouldn't you develop on the simpler platform? – PoloHoleSet May 05 '23 at 16:13
7

There's a lot of talks going on regarding the simplicity of asmx web services over WCF. Let me clarify few points here.

  • Its true that novice web service developers will get started easily in asmx web services. Visual Studio does all the work for them and readily creates a Hello World project.
  • But if you can learn WCF (which off course wont take much time) then you can get to see that WCF is also quite simple, and you can go ahead easily.
  • Its important to remember that these said complexities in WCF are actually attributed to the beautiful features that it brings along with it. There are addressing, bindings, contracts and endpoints, services & clients all mentioned in the config file. The beauty is your business logic is segregated and maintained safely. Tomorrow if you need to change the binding from basicHttpBinding to netTcpBinding you can easily create a binding in config file and use it. So all the changes related to clients, communication channels, bindings etc are to be done in the configuration leaving the business logic safe & intact, which makes real good sense.
  • 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.
  • 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. You can host your WCF services in Console, Windows Services, IIS & WAS, which are again different ways of creating new projects in Visual Studio.
  • 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.
  • You will always like to use Visual Studio for NET 4.0 or 4.5 as it makes life easy while creating WCF services.
  • The major difference is that Web Services Use XmlSerializer. But WCF Uses DataContractSerializer which is better in Performance as compared to XmlSerializer. That's why WCF performs way better than other communication technology counterparts from .NET like asmx, .NET remoting etc.

Not to forget that I was one of those guys who liked asmx services more than WCF, but that time I was not well aware of WCF services and its capabilities. I was scared of the WCF configurations. But I dared and and tried writing few WCF services of my own, and when I learnt more of WCF, now I have no inhibitions about WCF and I recommend them to anyone & everyone. Happy coding!!!

  • Yeah, I have to disagree that WCF is simple, comparatively, especially for handling incoming XML. It's great for handling JSON, but it seems a lot more complex for managing XML documents. Or maybe I'm missing something that no one has ever asked about or answered on here. – PoloHoleSet May 05 '23 at 16:14