WCF vs ASMX WebServices


kick it on DotNetKicks.com

This question comes up a lot in conversations I have with developers. 

“Why would I want to switch to ASMX services?”

One analogy I have come up with to explain the difference between the two is an airplane analogy. 

I associate ASMX services with a Cessna 150 cockpit and I associate WCF services with a 747 Jumbo Jet cockpit. 

image

I’ll be honest, I’ve never flown a plane but I think I’m smart enough to crank a Cessna 150 if I had to figure it out.  The above screen shot is a real Cessna 150 cockpit.  There are a few gauges, some knobs, etc.  Really not that bad.  And I think this explains ASMX really well.  ASMX services are easy to crank and jump start.  Think about it.  We take an existing Asp.Net website and add a file called “asmx”.  Any method we attribute with [WebMethod] magically turns into a service.  Objects we pass in and pass out that have public getters and setters will be serialized into XML.

   1: [WebMethod]
   2: public string FlyToDestination(Location loc)
   3: {
   4:     // up up and away
   5: }

The barrier to cranking and getting going with an ASMX service is really simple.  And because it is simple, we’ve adopted them on a massive scale.  Let’s turn our attention to WCF.

image

WCF is a jack of all trades.  Think of it like a large plane that can repurposed for hauling passengers, hauling cargo, military use or whatever.  We are dealing with a plane but it is all about how that plane is configured.  Because things can be configured a lot of ways with the WCF 747 plane there are a lot more buttons in the airplane cockpit as compared to the Cessna 150.  The flip side of this is that once you understand how to configure WCF you’ve got one of the most versatile plane in the world!

From a developers stand point, the same logic or code written in an ASMX service works in WCF.  The code between the curly braces is the same.  The bottom line in either case is a method gets called and an object gets passed in (we call this a message when talking about services).  The difference in WCF is we program to a specific contract.  Here’s the same example above done in WCF.

   1: [ServiceContract]
   2: public interface IAirportService
   3: {
   4:     [OperationContract]
   5:     string FlyToDestination(Location loc);
   6: }
   7:  
   8: public class AirportService : IAirportService
   9: {
  10:     
  11:     public string FlyToDestination(Location loc)
  12:     {
  13:         // up up and away
  14:     }
  15: }

Instead of attributing the specific method like we do in ASMX, in WCF we attribute the Interface.  Programming to an Interface is a good thing and the reason this is done is to loosely couple the host of the service from the implementation.  Doing this opens the door for hosting WCF services not only in IIS but console apps, Winforms, WPF, etc.  Since we’ve programmed to a contract (which is just an Interface), any class that implements the Interface can be a service.  This is powerful.  This is powerful because how we expose this service is up to us (again it is all about configuration).  Because we can expose our AirportService a number of ways we can see that WCF provides developers the ability to write code once and repurpose their code as needed. 

image

Exposing a WCF service requires a little more training from this point forward ( just like flying a 747) because we have to understand how to configure the service.  It is this little bit of extra effort required to understand WCF configuration that stops a lot of developers from using WCF.  This is a shame because when the developer using ASMX wants to guarantee message delivery, participate in transactions, or use binary serialization instead of XML, they’ve got a lot of work ahead of them as compared to WCF.   

The moral of the story is ASMX is simple and because it is simple, it isn’t very powerful.  Take the time to learn about WCF because this is the future of the .Net platform, thus it will be time wisely spent.  If you’ve been holding back I encourage you to step out of your old ASMX habits and learn the ways of WCF. 

If you would like to dig a little deeper with WCF I encourage you to check out my “Demystifying Windows Communication Foundation” power point.  In there you’ll find a lot more details about how WCF works.

http://keithelder.net/Presentations/DemystyfyingWCF/DemystifyingWindowsCommunicationFoundation.ppt

Happy messaging.

posted @ Friday, October 17, 2008 12:48 PM

Print

Comments on this entry:

# re: WCF vs ASMX WebServices

Left by Mitchel Sellers at 10/17/2008 1:53 PM
Gravatar

Awesome comparison between the two!

# re: WCF vs ASMX WebServices

Left by newman at 10/20/2008 8:58 AM
Gravatar

Another thing that is great about WCF is that its architecture forces you into writing more cleanly separated code. Even with ASMX web services good developers would separate their logic into an assembly using the service as just a communication mechanism.

WCF makes this easier to achieve by enforcing it in the architecture. You can easily use your WCF service classes just like a regular library. Doing so allows for better code reuse and the fact that your services are exposed over the network via[insert method here] it just a configuration detail.

# re: WCF vs ASMX WebServices

Left by Pete Brown at 10/23/2008 8:56 PM
Gravatar

If you want to get into WCF and create a service that is just about as simple as an ASMX service, create a new "Silverlight-Enabled WCF Service" (assuming you have the SL tools installed). That creates a WCF service that is SOAP 1.1, does not use a separate interface definition, and supports serializing additional types like, say, Uri, that ASMX does not. It sets up the config file for you as well.

You get Cesna controls on top of your 747 :)

Pete

# re: WCF vs ASMX WebServices

Left by Joe Brinkman at 10/26/2008 3:02 PM
Gravatar

One counter argument to WCF is that configuration of WCF by the web administrator is not a trivial excercise. More and more cr@p is getting shoved into web.config with each new .Net release, and what used to be manageable by your typical web admin is quickly becoming something that is only understood by web developers. This is not a good thing.

# re: WCF vs ASMX WebServices

Left by Sugandha at 11/4/2008 11:08 PM
Gravatar

Awesome..indeed :)

# re: WCF vs ASMX WebServices

Left by Zeeshan Umar at 12/17/2008 1:52 AM
Gravatar

Microsoft is now making things more complex. Consider the case of normal web admins. Can they configure the webconfig files, since WCF adds lots of configurations in webconfig file.

However technology is good I also view an article related to the performance of WCF and ASMX. Check out it:

geekswithblogs.net/.../65067.aspx

# re: WCF vs ASMX WebServices

Left by Woooah at 12/18/2008 11:04 AM
Gravatar

Nevermind WCF and ASMX..... whose flying the plane?!?!?!!!

# re: WCF vs ASMX WebServices

Left by Mirage at 1/6/2009 1:25 PM
Gravatar

Our WCF application does not use any webconfig at all. Everything is done programmatically, and user friendly UI's in the product allow relevant knobs to be turned.

Forcing admins to edit XML isn't a WCF problem, it's a software design and application development problem.

# re: WCF vs ASMX WebServices

Left by graffic at 2/22/2009 12:23 PM
Gravatar

The boeing 747 has 38 years of changes over it's body. WCF not so many.

I guess the idea of this post of "hey! do you trust in a boeing 747? trust WCF too" tries to generate a bit of missunderstanding.

WCF is new, and still lacks "things". But it will depend on your project. You'll be surprised about some common functionality missing on WCF.

Choose your tool carefully :)

# re: WCF vs ASMX WebServices

Left by Ivan TRoy at 3/24/2009 9:42 PM
Gravatar

Microsoft and WCF really sucks !!!, it does not provide WSDL 2.0 support nor 100% xml-schema compliance nor fully WSDL contract first design.

# re: WCF vs ASMX WebServices

Left by Kamran at 4/5/2009 2:51 PM
Gravatar

Yah Lacking support of WSDL 2.0 is a very disgusting thing.Other wise it's a great innovation of integrating nearly all type of communication

# re: WCF vs ASMX WebServices

Left by Havinski at 4/5/2009 3:14 PM
Gravatar

I don't get it, why are you two so bent out of shape of not supporting WSDL 2.0? That spec was just released in middle or late of 2007 and the development of WCF was already WELL underway.

I'm sure the teams are looking at the spec and figuring out what to do with it.

There's a lot of platforms that don't even support nested schemas like the WSDL's generated for WCF out of the box.

I don't see this as a big deal. Get over it and move on.

# re: WCF vs ASMX WebServices

Left by Darlingpretty at 4/22/2009 5:36 AM
Gravatar

You mean that WCF will replace .net remoting , i can see WCF architecture is pretty same as .net remoting.

# re: WCF vs ASMX WebServices

Left by TheElder at 4/22/2009 7:07 AM
Gravatar

@Darlingpretty

The architecture of WCF vs .Net remoting couldn't be more different. That's just one of the things WCF unifies as the communication platform.

# re: WCF vs ASMX WebServices

Left by Anonymous Coward at 4/24/2009 2:26 AM
Gravatar

WCF has some interesting ideas, but its layers of complexity pretty much cause it to screw the pooch, both in terms of programability and performance. All those layers of abstraction have a significant cost. At launch MS has was only able to claim about a 20% performance edge over standard web services, which begs the question of "why bother". In our experience at _major_internet_company_ WCF falls apart at any scale above small enterprise (~2000 users). If you're in the workgroup-to-enterprise pocket, maybe it offers something truly useful beyond what one could roll themselves, but I haven't found it.

# re: WCF vs ASMX WebServices

Left by TheElder at 4/26/2009 9:20 AM
Gravatar

20% isn't even close with the numbers you can achieve with WCF compared to ASMX depending on the situation.

I have a blog post I'm working on that will show how things compare. Stay tuned.

At your company you may be running into the built-in throttling with WCF. It is out of the box tuned down for DOS attacks. You have to chose a fair balance between what you want to allow.

Make no bones about it. It is more complex because, well IT DOES MORE. Having a single programming model is a huge will in my book. It is something we need and we're just seeing the surface scratched with WCF.

# re: WCF vs ASMX WebServices

Left by kumal at 5/31/2009 11:56 AM
Gravatar

thanks for the article. Agree wcf is lot more complex compared to asmx. But the fact that asmx is being phased out by wcf does not leave us any choice but to learn wcf, does it?

One question i have tho, yes understood wcf is more feature rich than asmx. but in terms of interoperability between platforms, and if our applications do not need all the additional features such as security, i can safely assume, asmx offers the same interoperability as wcf, yes?

# re: WCF vs ASMX WebServices

Left by TheElder at 6/2/2009 9:19 AM
Gravatar

Kumal,

There's something other than that to consider and that is speed or performance.

If you are going from .Net to .Net, meaning your server is .Net and all of the clients hitting your service is .Net, then you can or will get a tremendous speed increase using WCF over ASMX.

I have a sample app that I built that benchmarks the various bindings as well as asmx. A WCF service using netTcpBinding (which is a binary binding) processed 100 messages in 40 milliseconds. The exact same call made with ASMX was 323 milliseconds.

Even if you use the basicHttpBinding which is essentially what an ASMX service is you will still see a performance increase merely because WCF's serialization is faster.

# re: WCF vs ASMX WebServices

Left by kumal at 6/2/2009 12:32 PM
Gravatar

Thanks for the response, nice to know someone actually monitors their blog ;-)

I have also built an app to compare asmx and tcp performance, and to be honest (also i could be doing something wrong), i do see difference when sending a large amount of data, but not much difference when sending a smaller ones, is that expected?

Would love to see your benchmark, you have a link to the sample app?

# re: WCF vs ASMX WebServices

Left by Eran at 6/3/2009 3:54 PM
Gravatar

Can't read the ppt in any way

# re: WCF vs ASMX WebServices

Left by TheElder at 6/3/2009 4:03 PM
Gravatar

Kumal,

You definitely have something wrong as what you are implying flies in the face of computer science. Binary is just faster. I don't have a link to the sample app because I'll need to write up a whole article on just how to configure it. Which I plan on doing one day.

# re: WCF vs ASMX WebServices

Left by TheElder at 6/3/2009 4:06 PM
Gravatar

Eran,

There is a video of a prensentation I did of that deck this past week that you can watch (even better than getting just the deck) that I will share where I do this presentation. I'll update this once it is ready.

# re: WCF vs ASMX WebServices

Left by kumal at 6/8/2009 2:29 PM
Gravatar

dont hurt to ask..... would you mind if i send you my solution, and tell me what i am doing wrong?

# re: WCF vs ASMX WebServices

Left by Keith Elder at 6/10/2009 3:34 PM
Gravatar

No promises I'll get to it quickly but send it over, my email is on the about page. May make for a good blog post.

-Keith

# re: WCF vs ASMX WebServices

Left by Monsy A.K at 6/11/2009 7:47 AM
Gravatar

Nice comments on WCF. I think we can share more and more about the architecture and implementation about WCF. I am started the experiment. Lets see. I will post my doubts as the implementation progress. Its a good article

# re: WCF vs ASMX WebServices

Left by prasanthi at 7/12/2009 7:10 PM
Gravatar

cool

# re: WCF vs ASMX WebServices

Left by vinod at 7/14/2009 5:23 AM
Gravatar

Cool article.

# re: WCF vs ASMX WebServices

Left by NBstrat at 8/5/2009 5:19 AM
Gravatar

Forcing admins to edit XML isn't a WCF problem, it's a software design and application development problem.

AGREE!!! All web app's that I build include an easy to use admin/config section so even the most novice web admin can follow a set of simple instructions to get the app delivered and running. The small amount of time you devote to building this config portion of your app will pay off each time you drop it into the next application. Need more info/idea's? ask away.....

# re: WCF vs ASMX WebServices

Left by Genius at 8/7/2009 4:25 AM
Gravatar

Well, first of all good blog and nice comparison. no doubt WCF looks Future technology, but it's complex and need more time to grasp and then impliment. i am still not sure if i spend few weeks on study and then impliment WCF or hit the ground with ASMX web service and in 2-3 weeks finish the project.

can you through light on security of WCF. how good is? if possible comparison.

thanks,

Regards,

# re: WCF vs ASMX WebServices

Left by TheElder at 8/7/2009 8:22 AM
Gravatar

Easy. The comparison is, there isn't a comparison.

Really the best thing to do when it comes to WCF and ASMX is just look at this chart which outlines the bindings of WCF. Understanding and configuring bindings is what makes WCF more complex to learn (just like in a jet cockpit, this is where all the buttons and switches lie).

For a comparison, look at the "basicBinding". This is essentially the ASMX equiv in WCF.

Then look at the wsHttpBinding and the tons of others and the features they offer.

So really when you look at it from that angle, there really isn't a comparison.

Here is the link:

msdn.microsoft.com/en-us/library/ms731092.aspx


# re: WCF vs ASMX WebServices

Left by Aaron at 8/11/2009 7:21 PM
Gravatar

Well actually I was backing when hearding WCF because I didn't know what exactly it was and capable of. Now I know there is something great coming out actually already came out.

Thanks for the article. From now on I am on learning WCF at MSDN.

# re: WCF vs ASMX WebServices

Left by Abhinaw at 8/31/2009 2:13 AM
Gravatar

Hhuummm Gr8...I must say Very good comparison.

# re: WCF vs ASMX WebServices

Left by anonymouse at 9/18/2009 2:38 AM
Gravatar

Hi, when I try and download the ppt file it doesn't open (Office 2003, with 2007 Compatibility pack installed). If I rename the extension to .zip I can see there are contents (i.e. it is a pptx file) but it still cannot be loaded. Could you possibly upload the file as a zip - I think it is getting mangled in transit. Many thanks!

# re: WCF vs ASMX WebServices

Left by Naveed Anjum at 10/2/2009 5:37 AM
Gravatar

Really nice work. Now i can also differentiate them properly.... Thanx man

# re: WCF vs ASMX WebServices

Left by Murali Vaddiparthi at 10/22/2009 11:21 PM
Gravatar

Great article. Thanks to all buddies who shared their knowledge.

I have one question in my mind for a long time. Is WCF provides more secured services as compared to ASMX.

Cheers.

# re: WCF vs ASMX WebServices

Left by Jud at 10/23/2009 8:26 AM
Gravatar

@Murali

Yes, not even close.

# re: WCF vs ASMX WebServices

Left by Nigel Stratton at 11/13/2009 9:04 AM
Gravatar

Thanks for the advice it concurs with others. I will build this simple little project I need quickly in webservices and leave WFC for the right day.

# re: WCF vs ASMX WebServices

Left by saurabh at 11/19/2009 8:07 AM
Gravatar

Hi, It was a great article to kick start WCF understanding. I am using the web services for a long time and now want to switch into WCF. Can someone tell me how to convert existing web service into WCF service and what about the security.

# re: WCF vs ASMX WebServices

Left by TheElder at 11/21/2009 11:33 AM
Gravatar

To convert existing web services you will need to:

1. Extract an interface for the service (tools like Coderush and Resharper make this really easy).
2. Apply the proper attributes you need in this interface [OperationContract] and so on.
3. Implement that interface on your existing class file
4. Expose the service with the binding you want to use.

Tip: Put your interfaces in one DLL so they can be easily re-used.

This is a good question, I may do an article on this later on.

-Keith

# re: WCF vs ASMX WebServices

Left by TheElder at 11/21/2009 12:45 PM
Gravatar

The power point opens for me, not sure why it is not opening for you. Email me and I will send you a PDF version.

# re: WCF vs ASMX WebServices

Left by Saurabh at 11/24/2009 9:33 AM
Gravatar

Hi Keith, I appreciate your prompt response. It is really helpful. Here I have another question. How can we consume existing web service from the WCF service. Will it be in a same fashion we consume from web page. Can we deploy web service and WCF service on the same IIS (using WAS) server on the same port.

# re: WCF vs ASMX WebServices

Left by Bala at 11/24/2009 11:56 AM
Gravatar

Extremely Great !!

# re: WCF vs ASMX WebServices

Left by TheElder at 11/24/2009 12:31 PM
Gravatar

Maybe I'm missing something but just add a reference to your WCF service to existing web service, shouldn't be a big deal. Yes you can deploy web service and wcf service on the same IIS server (you don't need WAS to do this though).

Having a web service and wcf service in the same application are no different from having more than one aspx page in a web application. I think you may be over thinking this.

-Keith

Comments have been closed on this topic.
«February»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213