Showing posts with label ajax. Show all posts
Showing posts with label ajax. Show all posts

Tuesday, May 8, 2007

End of ASP.NET?

I just watched Scott Guthrie's Silverlight 1.1 screencast. It's very promising. It looks like they have everything to make the technology work and now they need to get everybody to take it seriously. I don't think they'll have a hard time with developers; it was a big hit at MIX '07. The harder part will be convincing people to install the plug-in or designers to learn Expression Blend.

Assuming it gains critical mass, will anyone continue to make regular ASP.NET HTML-based pages? Silverlight-based pages look better and are easier to develop. Javascript is a fun language but it's dynamically typed, embedded in the page instead of on the server and can't leverage existing .NET libraries. Not having to deal with cross-browser HTML quirks may be worth it.

I'm hoping Silverlight catches on.

Saturday, April 7, 2007

Web Services with Prototype and ASP.NET Ajax

Here's a link to the handler: http://www.subtlereality.com/wsproxy.ashx.html

As I've mentioned before, I don't like using ASP.NET Ajax's client code. I like using web services because they're easy to develop, but I can't find a good SOAP library for Javascript. This makes calling web services difficult. After waiting for a while for someone to write one, I decided to take my own shot at it. My project already uses Prototype, so I decided to use those AJAX tools. It was a lot easier than I thought.

My approach was to figure out how ASP.NET Ajax called the web services and use that method. It clearly knows how to do it. I rolled up my sleeves and delved into the JavaScript library and found.. no SOAP envelope in the entire thing. I dug deeper and found that it sends POSTs with a content-type of "application/json" and the body is a JSON-serialized object. That was easy enough.

The trickiest part was the date serialization. Nikhil Kothari explains the issue in this blog post. Microsoft used "@1234@" in the Atlas betas but switched it to "\\/Date(1234)\\/" which is a lot more frustrating because you need to count slashes and try to figure out how often your string is being interpreted.

In the end, I came up with a HttpHandler that mimics the ".asmx/js" files that ASP.NET Ajax uses. You need to pass in the path to the web service and the .NET class name as arguments through the querystring. For example:


It doesn't deserialize DateTimes as the return value and you don't have as much control over it. If other people start using this, I'll start a real website for it. Feel free to ask me any questions about it.

Thursday, March 8, 2007

ASP.Net Ajax as a Tool

Libraries are abstractions that make it easier to do things that can already be done. Sure, you could write your own code that parses XML files, but it's a lot easier, quicker and more reliable if you use one that someone else wrote. If that library doesn't work correctly or doesn't make the job easier, it's not usable. Flexibility is a bonus. It's useful if you can use the same library for image resizing and image format conversion but if there isn't one, you can just use two libraries. If a library is too inflexible, it becomes usable. A library that takes any image and resizes it to 32 x 32 isn't useful at all if I want 48 x 48.

ASP.Net Ajax is an odd case. It makes some thing extremely easy, and for that alone it's going to get wide usage. UpdatePanels are an extremely easy way to avoid whole page refreshes for minor changes and lower bandwidth usage. The Control Toolkit has a little bit of a learning curve but it's also a great tool to do some useful things on web pages.

It's almost a shame that the javascript libraries are a mess. They are extremely intimidating, and my attempts to dig into it have been discouraging. Javascript is a very lean and powerful language and I have to wonder if there's a benefit of a namespace and class system is necessary. The UpdatePanel and Control Toolkit is built on top of the javascript libraries, so I'm going to have them at my disposal and I may as well use them.

I want to use them. There are problems I'd like to solve that require Javascript and I don't want to bloat my site with more than one library. Specifically, I'd like to go to the server, do some processing, and send back code that modifies one element on the page, similar to Unobtrusive Javascript in Rails. The UpdatePanel is overkill, it will update the entire section. I don't think ASP.Net Ajax can do this explicitly and I would like to write and share an Unobtrusive Javascript control for that library, but I don't know if I will. It seems like it will be much easier to avoid using the javascript library and create a separate library that I would probably not share.