Wednesday, March 21, 2012

CascadingDropDown incompatible with WebServices using GET?

I'm using a trio of cascadingdropdowns representing country/state/city throughout a web application I'm developing for a client. They've recently reduced their internet speed dramatically (from 7mbps to 728k) and suddenly I've had to become more concerned about bandwidth usage.

I'd like to switch my webservice to use GET so that client browsers can cache the results without re-requesting from the server, unfortunately when I try, my select boxes show the error: 12030 (occasionally 12031)

WebService Code:

1<Services.WebMethod(cacheduration:=60), Script.Services.ScriptMethod()> _2Public Function GetCountries(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()3Dim cachedurationAs TimeSpan = TimeSpan.FromMinutes(1)4Dim maxageAs System.Reflection.FieldInfo = HttpContext.Current.Response.Cache.GetType().GetField("_maxAge", Reflection.BindingFlags.InstanceOr Reflection.BindingFlags.NonPublic)5 maxage.SetValue(HttpContext.Current.Response.Cache, cacheduration)6 Context.Response.Cache.SetCacheability(HttpCacheability.Public)7 Context.Response.Cache.SetExpires(Now.Add(cacheduration))8 Context.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate")9Dim cadapterAs New ltcodebehind.DSTablesTableAdapters.countryTableAdapter10Dim ctableAs New ltcodebehind.DSTables.countryDataTable11 cadapter.Fill(ctable)12Dim valuesAs New List(Of CascadingDropDownNameValue)13For iAs Integer = 0To ctable.Count - 114 values.Add(New CascadingDropDownNameValue(ctable(i).Title, ctable(i).ID))15Next1617 Return values.ToArray1819End Function

Client source code

1 <asp:ScriptManager runat="server" ID="acm1" >23 </asp:ScriptManager>4 <ajaxtoolkit:CascadingDropDown runat="server" ID="atlascascmgr" ServicePath="../Services/skService.asmx" SelectedValue="229" Category="country" ServiceMethod="GetCountries" TargetControlID="ddlcountry" />5 Country<br />6 <asp:DropDownList ID="ddlcountry" runat="server" />

Some notes

The only different on whether I receive an error 12030 is whether I have theusehttpget:=Truein the scriptmethod, so my cascadingdropdowns are configured properly for POST operations, I specifically need to know what I can change to get it to accept GET operations.

Usually its around this time that someone might offer up serverside caching, so I'm going to go ahead and answer that question now. 1) I appreciate the goodwill, I'm not being snarky, just trying to preemptively headd of the answer 2) I'm caching the webservice via the cacheduration:=60 up above, it just doesn't help because the server has power to spare, its the clients browsers that need the help.

Thanks everyone for their potential answers. :)

The third parameter to ASP.NET AJAX's Sys.Net.WebServiceProxy.invoke method is called "useGet" and tells it whether to use GET or POST for the web service call. The Toolkit's CascadingDropDownBehavior.js currently hard-codes this parameter to false (meaning "use POST"), so that's likely the source of the problem here. You should be able to change the value to true and rebuild for your client. If that works for you, pleaseopen a work item to ask that we expose this setting as a parameter to CascadingDropDown extender itself so that it will be easy to change for others who might want to do so. Thank you!

Very interesting, I'll do it when I have the time and if it works, open the work item like you describe.

Thanks!

No comments:

Post a Comment