Skip to content Skip to sidebar Skip to footer

Webmethod Return Values In Json Format

How to return values from Webmethod to the client in JSON format? There are two static int values that i want to return. Do I need to create new object with those 2 properties an

Solution 1:

I would just go with an object. It fits with what you need to do. If you have two return values you have to put them together in a structured way.

  public class StatusResult
        {
            public int StatusProcess { get; set; }
            public int StatusProcessTotal { get; set; }
        }

  [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public StatusResult GetStatus()
        {
            int statusProcess,statusProcessTotal;

            //Status.Lock.EnterReadLock();
            statusProcess = 5;
            statusProcessTotal = 1; //Static field        


            var result = new StatusResult();
            result.StatusProcess = statusProcess;
            result.StatusProcessTotal = statusProcessTotal;

            return result;
        }

Post a Comment for "Webmethod Return Values In Json Format"