Monday, March 2, 2015

Comparing ASMX and WCF


It’s known that WCF will provide the functionality of WS-* standards in an easier way than previously was possible. But as these standards were not supported on most development platforms and provide features that are not needed by default in most of the web services. Most of the services are using SOAP basic profile which can be implemented using both WCF or plain old ASMX.
Here is a comparison between using both technologies to create a web service with basic profile binding:

Feature ASMX WCF Comments
Easy to learn and code Both have similar attributes that are added to service and data classes
Easy to configure
WCF adds a hell of configuration keys with different options that mostly are not useful
Easy to deploy
With the complex configurations and options of WCF, its relatively hard process to deploy a WCF service
Easy to browse and test
ASMX services provide a page to easily browse the services operations and enable users to test these operations from the browser.
It also shows a full sample of the SOAP HTTP message to call the service simplifying the life for developers who are trying to send these requests manually (mostly because their development platform doesn’t support it)
Easy to debug errors
Using WCF introduces a set of ambiguous exceptions that maximize the complexity of working with the technology.
Compatibility with older .NET Frameworks
Trying to call a WCF service from .NET Framework 1.1 or 2.0 is a bad scenario
ASP.NET Context In WCF this is off by default, so you have to add some compatibility configurations to be able to access the ASP.NET context which contains: Cache, Session, Cookies, Request headers specially host address
Support for JSON data format Both added JSON support in .NET 3.5 to support calling the service from javascript
Support for WS-* standards
A plus for WCF where it will be a very big hassle to work with WS-* with ASMX
Support for binary data format
Although it’s not recommended but it could be useful for bandwidth to use binary instead of XML with WCF
Support for REST
Don’t confuse REST with JSON as REST is the way HTTP requests are sent with parameters in URLs and using multiple HTTP actions instead of just GET.

I’m not sure that ASMX doesn’t support REST so if anyone has more information please post your comments.
Intercepting messages across the service/client
WCF support creating code that run in certain events to intercept messages and process them across all service operations.

This is not available in ASMX and could be useful in certain complex scenarios like doing custom authentication, authorization, logging and routing techniques.
Customizing client side functions
WCF enables you to take the service interface through a class library and use it to call the service without adding a service reference (using a dynamic channel factory). This allows using the same data classes in both the service and client, making it possible to include functionality in these classes (like caching, validation or auto calculated properties) that can be used on the client side.

This can’t be done using ASMX as it can only be called from the web reference which creates a copy of the data classes (taking only fields that are transferred on wires) without any functionality that was on the service classes.
After this comparison, my recommendation is the following: if you are using SOAP Basic Profile which is the most probable, always use ASMX for it’s simplicity and ease of use unless you need a feature that only exists in WCF. This will save you a lot of trouble.
Note: Another tip, if you are already using WCF with the default binding wsHttpBinding and you are not making use of any special feature of this binding (using only features like old ASMX). It’s better to change this binding to httpBasicProfile as this will greatly enhance the performance of your service.

Ref: http://www.bishoylabib.com/2009/08/comparing-asmx-and-wcf.html

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More