Web services are those services which are available over web to communicate between systems.
By default Web Service returns data in XML format, now if the requirement is to return in JSON format then we need to do modification in web method.
Below webmethod returns data in JSON format.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string UserRegisteration(string uname, string mobile, string email, DateTime dt)
{
List<Result> listResult = new List<Result>();
ResultobjResult = new Result();
//Your logic here
objResult.Message = “Success”;
objResult.Status = true;
listResult.Add(objResult);
return new JavaScriptSerializer().Serialize(objResult);
}
public class Result
{
public string Message { get; set; }
public bool Status { get; set; }
}
Below namespaces require to build above code successfully:
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;
Read this - What is Microservice Architecture?
Related Blogs –
- Web Services, SOAP and RESTful Services
- Get JSON data in Web Service
- How to create a secure Web Service?
- How to overload a web method in Web Service?
- Web Service in InfoPathForm – SharePoint 2010
Nice post Thanks for sharing it
Hadoop Training in Chennai
I m a fresher developer. your blog helps me a lot. Code snippet posted here is helpful for me.
Well explained, good code snippet on web service methods.
Thanks for your comment.
Thank you for your feedback.
Thank you for your nice feedback.
Great articles, first of all Thanks for writing such lovely Post! such great & useful knowledge you mentioned here.
Dot Net Training in Chennai
Selenium Training in Chennai
Hadoop Training in Chennai
very useful post… thank you for giving this post….
inplant training in chennai
inplant training in chennai
inplant training in chennai for it
Australia hosting
mexico web hosting
moldova web hosting
albania web hosting
andorra hosting
australia web hosting
denmark web hosting