Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 254
Juan David Nicholls Cardona Avatar asked Feb 13 '13 22:02

Juan David Nicholls Cardona


People also ask

What is the difference between Asmx and ASPX?

Unlike ASPX files which contain the code for visual display of ASP.NET webpages, ASMX files run at the server in background and perform different tasks such as connecting to database, retrieving data, and returning it in a format in which the request was made. These are used specifically for XML webs services.

What is ASHX and Asmx?

An ASHX is a generic HttpHandler. An ASMX file is a web service. ASHX is a good lean way to provide a response to AJAX calls, but if you want to provide a response which changes based on conditions (such as variable inputs) it can become a bit of a handful - lots of if else etc.

What kind of files are ASHX files?

ASHX files are files used with ASP.NET programming and can be opened with any program that codes in ASP.NET, such as Microsoft Visual Studio and Microsoft Visual Community. As they are text files, you can also open ASHX files with a text editor program.


1 Answers

.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.

like image 94
Jesse Webb Avatar answered Sep 21 '22 04:09

Jesse Webb