I was at Tech-Ed South Africa this year (2009) and I saw a very impressive demo by mmmmh, I think it was John Carter from http://lostintangent.com
He was doing an introduction to Ajax 4.0 in particular the new Data Context. Well I must say I was quite impressed, I don’t know about you but I really don’t like the current MS Ajax implementation. The update panel which has been widely adopted as the Ajax control of choice by many .net developers, although it is easy to use it comes with a very high bandwidth cost.
After Tech-Ed I had a look around and tried to find a nice sample of the demonstration that Jon gave but alas there was nothing to be discovered. So after about four hours of searching I did what any respectable developer would do, that’s right I grabbed all the little bits and pieces of that that I could lay my grubby little fingers on and started building my own.
Some background info?
DataContext is an object that is capable of consuming a server-side resource that serves JSON or XML data. It will then store it on the client site and you can bind it to sys-template, manipulate it and commit the updated data (just the updated data). If you want real details on it click here
Demo project?
To show you how much better the new 4.0 Ajax implementation is project will use normal html file and not aspx files.
The project has three JavaScript files MicrosoftAjax.debug.js, MicrosoftAjaxAdoNet.debug.js, and MicrosoftAjaxTemplates.debug.js file these are the Ajax libraries and it uses the .net Entity framework to create the service layer and two htm sample files, they use different methods
The js file are all .debug files this is to allow intelisense for JavaScript, you will see that that they have /// xml comments.
Download and unzip the sample code If you don’t have NorthWind database the restore the backup that I have included in the App_Data folder. Make sure that the web.config is set up correctly and check the NorthwindEntities connectionString If you have problems you might want to recreate the manWindDataService layer again and that should be about it.
Download:
Click here to download the sample project.
References:
http://lostintangent.com
http://msdn.microsoft.com/en-us/magazine/cc163413.aspx
Possible problems & resolutions
If you cannot browse to the manWindDataService.svc file and you are getting a 404.3 error.
Description: The page you are requesting cannot be served because of the Multipurpose Internet Mail Extensions (MIME) map policy that is configured on the Web server. The page you requested has a file name extension that is not recognized, and therefore is not allowed.
Error Code: 0x80070032
Notification: ExecuteRequestHandler
Locate “servicemodelreg.exe” it should be in the “Windows Communication Foundation” folder. Once you have located open cmd and run “cd C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation“ and then servicemodelreg –i
Then you might get another error, “The application domain or application pool is currently running version 4.0 or later of the .NET Framework. This can occur if IIS settings have been set to 4.0 or later for this Web application, or if you are using version 4.0 or later of the ASP.NET Web Development Server. The
This is because the IIS App Pool is now running under .net 4.0.
1. Open IIS 7.0 Manager
2. Open “Basic settings” and find Application Pool Name
3. Open Application Pools
4. You can see that after installing .NET framework 4.0 all Application pools are updated to run under .NET Framework v4.0
5. Find application pool from step 2, click Basic (or Advanced) Settings from the right panel.
6. AND FINALY change it to “.NET Framework v2.0.50727” click “OK”
7. THAT’S IT !!!
