views:

476

answers:

2

I'm setting up my site to receive info from people via text message. The way it works is they text a number, that service then sends an HTTP POST to a url I specify. I've heard that .asmx files are better than .aspx files because they don't go through the whole page lifecycle. However, I don't really understand how to get a .asmx file running, and can you even call it with a POST, ie, www.mysite.com/webservice.asmx? I know I can make it work with a .aspx file, but I wanted to check to see if there was a better way before I undertake this endeavor.

Thanks for your insight!

+5  A: 

While any extension can be mapped to any handler in ASP.NET, by default .aspx is mapped to page handler and .asmx is mapped to Web service handler. I think you are looking for .ashx which represents a generic simple handler. You just need to implement ProcessRequest method of the IHttpHandler interface after adding one to your project (Add New Item -> Generic Handler).

The .ashx works well if you want to manually process the request. Only if you want to provide a Web service (e.g. SOAP), you should go with .asmx. As a consequence, the best solution depends on the format of the HTTP POST request they send. If they send raw data in POST with their own specific protocol, go with .ashx. Otherwise, if they are using a standard RPC (SOAP, XML-RPC, ...) protocol, .asmx is probably better.

Mehrdad Afshari
how do i implement a .ashx? i have no idea...
Jason
This site has a good overview: http://www.15seconds.com/Issue/020417.htm
rifferte
Add a "Generic Handler" into your Visual Studio project. It'll create a template and you just begin writing code the reads from `context.Request` and does some stuff.
Mehrdad Afshari
do i call it like www.example.com/service.ashx?
Jason
Jason: Yes, like any HTTP URL.
Mehrdad Afshari
A: 

Create an .asmx file with Visual Studio. It should create a template with a HelloWorld method. Browse to it with your favorite browser and you'll actually get an explanation on how to post requests to it using various methods.

There is another type you haven't mentioned: ashx. However, in your case, a webservice (asmx) would make sense.

Thorarin