MSDN Magazine - February 2008 - (Page 46) the ClientStateFieldID property. EnableClientState is a Boolean property that controls whether client state is enabled. Building an Autocomplete Web Service A Web service that works with the AutoComplete extender is an ASP.NET AJAX script service. It looks nearly the same as a regular ASP.NET Web service except that its class must be decorated with the ScriptService attribute. If you employ a Web service that lacks the attribute, each request to the associated ASMX endpoint causes an HTTP 500 error. While an exceptions interface is not shown to the end user (the extender manages to always degrade gracefully), no flyout with suggestions is ever displayed either: [ScriptService] public class SuggestionService : WebService { } Note that while the script service doesn’t require the WebService attribute, it can still use it to provide namespace information. The name of any public method on the script service class that is flagged with the WebMethod attribute can be successfully assigned to the ServiceMethod property on the extender. A method that provides suggestions must have the following signature: [WebMethod] public string[] GetSuggestions(string prefixText, int count) The first argument is the prefix text to generate suggestions. It matches the current content of the textbox, and its length is not smaller than the value of the MinimumPrefixLength property. The count parameter indicates how many suggestions are to be provided. The value of the count parameter comes from the value of the CompletionSetCount property. If you plan to take advantage of the context key, which is a String property that indicates any page or user-specific information to pass to the bound Web service, then you should provide an override for any Web service methods you intend to use. Here’s the signature: public string[]GetSuggestions( string prefixText, int count, string contextKey) { } The return value is always packed as an array of strings. Because of the ScriptService attribute, any communication between the server and client occurs through JavaScript Object Notation (JSON) strings. You can leverage any supported attributes on Web service methods to improve the service’s performance. For example, the CacheDuration attribute on the WebMethod attribute can force the service to cache the response of the method call for a specified duration. Likewise, you can enable session state if strictly required by the method’s logic. Figure 4 shows a sample service that offers suggestions on the customer name, which is coming from the Northwind database. A call made to a Web service every few characters typed may sound like a bad idea from a performance perspective. There are some factors, though, that make autocompletion more affordable than you might think. Client-side caching for the AutoComplete extender is based on local memory and is never persisted through a 46 msdnmagazine Cutting Edge http://www.scaleoutsoftware.com http://www.scaleoutsoftware.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.