Using RouteUrl to create clean URLs for CallbackMethods

In the previous topic I showed examples of how to call the service using verbose querystring syntax. By including the right parameter names like CallbackMethod or Method and matching parameters with a query string you can directly access service methods.

Another and cleaner way to do this is to use a RouteUrl you can attach to a CallbackMethod's attribute. For example the stock quote example can be set up like this:

public StockQuote GetStockQuote(string symbol)
    var stocks = new StockServer();
    var quote = stocks.GetStockQuote(symbol);
    if (quote == null)
        throw new ArgumentException("Invalid symbol passed.");

    return quote;

This creates a custom route to the callbackhandler which can then be accessed like this:


This is a lot cleaner and allows for specifying exactly how requests are fired.

Specifying Allowed HttpVerbs

You can also specify which Http verbs can access the method. By default methods accept all HTTP verbs but you can explicitly override to restrict access:

                AllowedHttpVerbs=HttpVerbs.GET | HttpVerbs.POST)]

© West Wind Technologies, 1996-2016 • Updated: 12/19/15
Comment or report problem with topic