I recently had some trouble with the .NET AJAX Toolkit AutoComplete Extender which did not seem to be working despite copying all of the code directly from the documentation. I discovered two missing pieces that were not obvious (to me at least).
The first is that I was trying to use a ServiceMethod without a ServicePath - according to the documentation this should allow using a method within the same aspx page as the callback method. I would imagine that this could work however getting the aspx page to act as a web service wasn’t critical for my purposes and so I didn’t try very hard to get it working. Instead I wrote a separate web service class for the callback as is shown in the documentation.
The second issue had to do with the .NET attributes that must be included. The documentation provides the following example for the method (note the “WebMethod” and “ScriptMethod” attributes):
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
Public string[] GetCompletionList(string prefixText, int count) { … }
What is less obvious, however, is that the web service class is required to have an attribute as well. A “ScriptService” attribute is require like so:
[WebService(Namespace = "http://www.verysimple.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
I found this useful bit of info in the development forums but it would have saved me about four hours of suffering if it was just included on the example page. Simply adding this attribute solved all of my problems and the autocomplete extender worked perfectly
In the process of solving this error, I used a handy utility by the name of Fiddler which allows you to spy on all of the HTTP traffic. I had initially suspected that the autocomplete javascript was simply not making the AJAX post because I couldn’t detect any activity using a javascript debugger and no javascript exceptions were being thrown. Using Fiddler, I saw the post was in fact being made. This is extremely useful for AJAX applications because you can see the raw output of the web service as it is being requested - which in my case contained some run-time errors. The autocomplete control seem to just quietly choke when the webservice fails.
One thing to note about Fiddler is that, though it works with any browser, only IE works right out of the box without some manual configuration. I put my other browser away for a bit and used IE. Another useful tip is that Fiddler didn’t seem to intercept traffic when using “localhost” as the hostname. When I used my local IP address, however, (for example 192.168.1.25) it worked perfectly.
Please feel free to post any comments. In particular I would be interested to know if you are able to use the aspx page as the ServiceMethod without creating a separate web service.
Share This