You ever have one of those days when just nothing wants to go right? A couple of days ago I was working on my session code for ASP.NET Connections. One of my sessions is on Dealing with Long Running Requests and one of the examples uses AJAX to offload the processing to messaging engine and optionally a separate process/machine. I've had this demo around for some time and originally I built it using Microsoft AJAX Beta 2 or one of the release candidates.
So I dusted off the old demo and sat down to update it for the RTM version which should have been pretty quick. The first part was getting a Web.config file that actually has all the MS AJAX settings in them. The original Web.config had the beta settings so I thought the easiest way to do this was to create another project that is all set up for MS AJAX and then copy that web.config into the current project (after renaming the old one) and then simply migrating my actual configuration settings ( ConnectionStrings, AppSettings, and one handler) over to the new web.config.
I also had to tweak a number of replaces for $() syntax to $get() and a couple of changes in one of the client side controls used in the sample's JavaScript code. That's where I thought it would end.
Well it didn't. The sample uses JSON callbacks using PageMethods, which saw some changes late in the MS AJAX cycle. PageMethods were made static so they no longer ran in the context of the page at all (which kind of defeats the whole purpose of PageMethods in the first place - the old feature set allowed for access to the controls of the page and full POST data). Again so had to make some adjustments to the code to change to static methods and make sure that each of the methods actually was stateless and didn't use any of the form's objects (like the MessageManager). Again no big deal.
But at that point the page still would not work. Whenever I'd run the page, I'd get a JavaScript errors saying that PageMethods is not defined. Quickly checking the network trace with FireBug confirmed that the script resource that normally contains the AJAX JSON proxy never got created.
I checked:
- Methods marked as [WebMethod]
- Web Methods are static
- ScriptManager on page
- EnablePageMethods set on the script manager
No luck. I checked, re-checked my settings but no matter what I tried it just... would... not... work. I even went so far as to create a new page dropped a script manager on it, created a couple of WebMethods and called them from client script to make sure I wasn't doing something wrong and sure enough that worked just fine. It's just in the particular page that it wouldn't work.
Eventually - after about an hour of screwing around with this - I just created a Web Service and called that instead and that worked immediately. I honestly don't know what was wrong with that page if anything. I even called a friend of mine to check out the page with GotoMeeting (in case I couldn't see the forest for the trees 'ya know - wouldn't be the first time) but he didn't see anything either.
So... anybody ever seen this before? PageMethods not working on a page failing to send the proxy code to the client?
In the end I suppose that's a good thing anyway. PageMethods became pretty much useless anyway when they became static in RTM. There's really no benefit for using them (other than keeping your code encapsulated in the Page which is questionable to begin with) and it actually made the sample a bit cleaner. The message service checking and processing code now all runs in the service class which is easier to demonstrate separately anyway - once you find it buried in the APP_CODE directory...
Other Posts you might also like