How wwCallbackHandler works

Create a new JSON service by creating a new HTTP handler and subclassing it from wwCallbackHandler. You can use .ASHX handlers or standard web.config routed handlers in an assembly. Once subclassed any methods that are marked with the [CallbackHandler] attribute can be accessed for remote JSON service functionality.
When you implement your handler, make sure you remove your base handler implementation ProcessRequest method or call base.ProcessRequest to ensure the base behavior is fired.

<%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Web; using System.Web.SessionState; using Westwind.Web.Controls; public class Handler : Westwind.Web.Controls.wwCallbackHandler // , IRequiresSessionState { [CallbackMethod] public string HelloWorld(string Name) { return "Hello " + Name + "! Time is: " + DateTime.Now; } [CallbackMethod] protected decimal AddNumbers(decimal x, decimal y) { return x + y; } }

Note that if you require session state you'll need to enable the IRequiresSessionState interface explicitly. In service scenarios this usually shouldn't be required.


Make sure to the TargetCallbackType of the wwMethodCallback Control

If you're using the wwMethodCallback control for your callback handling to an external handler it's necessary to let the control know the type information of the handler so it can properly generate the client proxy signatures for you. This is optional since the client proxy is not required, but it's very useful to simplify callbacks.
To assign the handler type use the TargetCallback property of the wwMethodCallback control and assign it the type of the handler:

protected void Page_Load(object sender, EventArgs e) { // *** Must assign the target type for the callback control // *** otherwise it can't create the proxy this.Callback.TargetCallbackType = typeof(Handler); }

This property must be set in code and cannot be set via markup since an actual type instance is required.

Handler Creation

Http Handlers can either be created as .ASHX files with or without Codebehind or as standalone handlers. .ASHX handlers are easy because no set up is required - simply create a new .ASHX file and create your class and then call the ASHX file via URL.

To create a standalone Http Handler, create a class and inherit it from wwCallbackHandler. Then register the class in web.config as an Http Handler:

<system.web> <httpHandlers> <add verb="*" path="MyService.axd" type="Westwind.Web.Samples.CallbackHandler,WebSamples" /> </httpHandlers> </system.web>

(in IIS 7 Integrated mode use the <handlers> section instead):

<system.webserver> <handlers> <add verb="*" path="MyService.axd" type="Westwind.Web.Samples.CallbackHandler,WebSamples" /> </handlers> </system.webserver>




  Last Updated: 3/11/2008 | © West Wind Technologies, 2008