Tag Archives: asp.net

How To Build a JSON Web Service to Send Mail in ASP.Net

I was pleasantly surprised to see the traffic analytics on a post I wrote a while ago on Using jQuery to Send Email with Web Services. However, I found some who were still requiring assistance writing the actual .NET web service. Here you go.

In Visual Studio, when you create a web service (ASMX), the default format is SOAP. You will need add a couple of attributes to the code to make it return results in a true JSON format.

  1. First requirement is that you do a POST, but the AJAX call already takes care of that.
  2. Your class is going to need the

    attribute so that you can call the web service from javascript.

  3. Your method responsible for sending mail will need this attribute:
    [ScriptMethod(UseHttpGet = false,ResponseFormat = ResponseFormat.Json)]

Continue reading