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.
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.
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.
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.
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With