A Programmer's Dream

Prototype and the Web Service

Posted by Stephen Wrighton on 16 May 2008

I'm a .NET programmer. Fundamentally, that's just what I do. Yet, I have a secret. It's a dark one for a .NET programmer, but I have it nonetheless.

I hate ASP.NET AJAX.

It would probably be more accurate to say that I despise it.

With a passion.

It's bloated, and It's never behaved as I expected it to. Maybe it's because I learned AJAX by rolling out my own implementation and then finding Prototype, FLEX and MooTools before finally settling down and really learning Prototype well enough that I can use it without constant references to it's API documentation.

I was doing that while Microsoft was trudging along with Atlas.

What's worse is the fact that ASP.NET AJAX just doesn't downgrade well. I'm a big proponent of the HIJAX style of AJAX implementation, meaning that it's built without all those fancy doo-dads, and then they get layered in, and the CLICK events for buttons and links get hijacked and used for AJAX-style goodness.

Yet, while working this way, I have struggled often against an issue with using Prototype library within .NET. Mainly the fact that Web Services did not want to play nice.

That, and only that, was the reason that I consistently went back and suffered with Microsoft's bloated variety of AJAX.

But, I've solved THAT problem.

Web Services' webmethods are nothing more than functions which return SOAP messages. Which means that they are accessed via a standard HTTP POST. Now, that's not a problem at all. Prototype's AJAX functionality has that down pact. The problem is all that SOAP XML which the web service wraps around the JSON that I'm actually returning.

Well, I finally actually, read that full page that is displayed when you're testing a web service through the browser. Oddly, the information I needed most to solve this problem was way down at the bottom. Which means I had to scroll to see it.
Yes, that little blurb tells you not only exactly what to send, where to send it, but ALSO the exact format of the SOAP messages that is being returned wrapped around my JSON string.

One could almost hear my cold, dead contractor's heart patter in my chest.

While it is not the most ELEGANT solution, as that would involve actually parsing the XML to retrieve my JSON, I merely did a quick replace on the XML tags, substituting an empty string in their place. A quick evalJSON call later, and lo an behold I have my JSON object running happily.

Tweet me @kidananubix if you like this post.

Tweet