<%@ 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.
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.
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>