Makes it easier to create web services that will be used with ajax, especially in Web Forms.
C# JavaScript ASP Puppet Boo Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
src
tools
.gitignore
README.md
build.bat
build.boo

README.md

Simple Service

Features

  • It's simple!
  • Created to make it easier to integrate ajax in ASP.NET Webforms websites.
  • Has a proxy for JavaScript use, which creates all service methods as JavaScript methods.
  • Can return controls as HTML.
  • Extendable with own ServiceResults, like in ASP.NET MVC.

Usage

  1. Create a new class.
  2. Inherit from SimpleWebService.
  3. Create a new public method that has return type ServiceResult.
  4. Inside the method, write the following code:
    return Json(new { hello = new { hello = "world" }});
    This will return a json object. You can also return Error(), Control(), Content() and JavaScript()
  5. Done! You can navigate to the service page to get information about methods.

JavaScript Proxy

To use the JavaScript proxy, simply include a reference to the service:

<script src="/services/sample/proxy.min.js" type="text/javascript"></script>

After this you can use all methods in the service like they were JavaScript methods:

<script type="text/javascript">
   var service = new SampleService();
   service.helloWorld("codingbug", function(response) {
      alert(response.value); 
   });
</script>

Sample Service

public class SampleService : SimpleWebService
{
    public ServiceResult HelloWorld()
    {
        return Json(new { hello = "world" });
    }

    public ServiceResult ContactUs(string sender, string senderEmail, string message)
    {
        bool success = SendContactEmail(sender, senderEmail, message);

        if (success)
            return Json(new {message = "Your message was sent."});

        return Error("Your message could not be sent.");
    }

    public ServiceResult GetPagedComments(int page, int pageId)
    {
        return Control<CommentList>("~/Templates/Shared/CommentList.ascx", control =>
        {
            control.CurrentListPage = page;
            control.CurrentPageId = pageId;
        });
    }
}

App_Start/SimpleService.cs

public static class SimpleService {
    public static void RegisterRoutes(RouteCollection routes) {
        // will automatically map all services in loaded assemblies.
        routes.MapSimpleServices();
    }

    public static void Start() {
        RegisterRoutes(RouteTable.Routes);
    }
}