Simple Service

Quickly create slim web services in ASP.NET Web Forms that can return Web Controls as HTML.


Simple Service was created to enable developers to more easily create web services in ASP.NET Web Forms, like how it's done in ASP.NET MVC.

Besides being able to return JSON it can also return Web Controls as HTML, and has a JavaScript proxy that enables you to quickly consume the service.

An example implementation of a service could look like this.

public class MySampleService : SimpleWebService
{
    public ServiceResult HelloWorld()
    {
        return Json(new { hello = "world" });
    }
    public ServiceResult GetPagedComments(int pageId, int page)
    {
        return Control<CommentList>(control =>
        {
            control.CurrentListPage = page;
            control.CurrentPageId = pageId;
        });
    }
}

To consume the service in JavaScript you could use the proxy.

<script src="/services/mysample/proxy.min.js" type="text/javascript"></script>
<script type="text/javascript">
   var service = new MySampleService();
   service.getPagedComments(1001, 1, function(response) {
      alert(response.value); 
   });
</script>