What is the difference between ashx, asmx, axd + cs(handler), webmethod(in aspx) and async methods in asp.net framework 4.5?

Juan David Nicholls Cardona picture Juan David Nicholls Cardona · Feb 13, 2013 · Viewed 10.4k times · Source

I need to know the technical difference of those files. Which one is the best option? When and why should we use it? I need a human answer, not the MSDN links.

Answer

Jesse Webb picture Jesse Webb · Feb 13, 2013

.ashx files are used for handling HttpRequests and modifying HttpResponses; you can pretty much make them do whatever you want. I have seen them used for things like serving PDFs and doing server-side processing and then redirecting. See here for more info.

.svc files (which were not mentioned in your question) are part of MS's new Windows Communication Foundation which is for SOA development. WCF supports SOAP, REST and a lot of other cool stuff.

.asmx files are an older means to host SOAP services. They are often accompanied by asmx.cs files (or .vb) which contain the actual methods behind the service. See here for more info. This is a legacy technology and I would recommend using WCF instead in new development.

[WebMethod] attribute is used to denote the methods surfaced in a SOAP service hosted by an asmx. See here for more info.

The .axd extension is used by generated web services used for many different things. (E.g. MVC3 uses axd web services to serve MS specific javascript) I don't think you would ever create an axd file, but I could be wrong... at least I never have. See here for more info.

Which one is the best option?

They are different tools used to solve different problems. When and why you should use each one depends on the job you are trying to accomplish. Lower level handling of your web application's behaviours can be achieved with ashx files. If you want to provide more standardized services, I would recommend using WCF and svc files. Please provide us with more information about the task you are doing so we can help you pick one.