Building Twitter Search using the ASP.NET Ajax Library Beta – Part 1

Last week we launched the ASP.NET Ajax Library Beta during PDC, oh and we donated it to the CodePlex Foundation under new BSD license (FTW).  As the email volume has been fading away running up to Thanksgiving in the US and everyone at work is recovering from conferences, I took this golden opportunity to sit down and build a small sample with the new library now that we are in Beta.

Since the ASP.NET Ajax Library takes care of JSONP requests for me (which enables cross-domain service requests) it is really easy to hit a service like the Twitter Search API which in turn provides me with a JSON result and a callback to trigger functionality which does something with the result.

This allows us to build a Twitter Search application that is running completely on the client-side depending on no servers apart from those at Twitter HQ (we kind of need them for the search results, remember).  In Part 1 of this 2-part series I will look at how to call the Twitter Search service using the WebServiceProxy.invoke method and then in subsequent posts I will look at using the data once in a DataView and how we can use client-side template to render the results.

First we start by exploring the WebServiceProxy.Invoke method – which is how we call the Twitter APIs.

  1. Sys.Net.WebServiceProxy.invoke("http://search.twitter.com/search.json?q=@jsenior", null, true, null, doSomething(result));

The above code will make the required call to the Twitter Search API and takes a few parameters including an onSuccess callback function (doSomething) so we can then do something with the result set.  We can also specify things like the methodName (for webservice requests), query parameters, timeout etc – for the full set of params check out the MicrosoftAjaxWebServices.debug.js file.  Behind the scenes, the invoke method figures out if you are making a request cross-domain in which case we require the call to be JSONP so we can receive the callback on our end.

To get access to WebServiceProxy.invoke we need have referenced a number of scripts from the ASP.NET Ajax Library including MicrosoftAjaxWebServices.js.  The most sensible way to do this is to use the new Script Loader which takes care of loading not only this particular script but also any others from the library on which it is dependant.  It does this in a really efficient way both in parallel and asynchronously allowing scripts to be loaded but not executed according to a dependency tree.  Furthermore, you don’t even need to reference the Script Loader from a local folder or web server, you can grab it direct from the Microsoft Ajax CDN:

  1. <script src="http://ajax.microsoft.com/ajax/beta/0911/start.debug.js" type="text/javascript"></script>

You’ll notice that we do versioning based on year and month so that your apps won’t break when we bring out new versions.

Once you’ve got the Script Loader referenced from the CDN, you can start bringing in the components you need and in this sample, so far, we need Sys.scripts.WebServices.  We use Sys.require to tell the Script Loader that’s what we need and also can provide a callback function for it to call once everything has been loaded and we are good to start using the script.

  1. Sys.require([Sys.scripts.WebServices], callback);

If we put all this code together and push one of the result tweets into a simple alert to show that it works, we get the following code:

  1. <script src="http://ajax.microsoft.com/ajax/beta/0911/start.debug.js" type="text/javascript"></script>
  2.     
  3.     <script type="text/javascript">
  4.  
  5.         Sys.require([Sys.scripts.WebServices], function callback() {
  6.             Sys.Net.WebServiceProxy.invoke(
  7.                 "http://search.twitter.com/search.json?q=jsenior",
  8.                 null,
  9.                 true,
  10.                 null,
  11.                 function (result) { alert(result.results[0].text) });
  12.         });
  13.  
  14.     </script>

Try it yourself by copy and pasting it into a blank HTML document, it’s that easy.

In the next post, I’ll show you how to do something useful with the result set by using the DataView component and client-templates.  Stay tuned.

For more information about the ASP.NET Ajax Library including samples, downloads and docs check out the wiki here: http://www.asp.net/ajaxlibrary

*UPDATE*

There is a bug in the beta where you need to include the following method to get the sample working.  Sorry to those who’ve been having trouble getting it working.  Add this to your javascript code and all will be right in the world.

// Workaround for a bug in ASP.NET Ajax Beta, you don't need this in the final version
        function createElement(tag) { return document.createElement(tag); }


Tags:

Building High Performance Web Applications

At the PDC (our dev conference) we release the Beta version of the ASP.NET Ajax Library and also donated it to the CodePlex Foundation as their first project.  For this version of the library we’ve focused on four areas of functionality:

Power for developers

Performance

Interoperability

Extensibility

Getting detailed about Performance

Dan Wahlin and I put together the following whitepaper that talks about how you can use the features in ASP.NET Ajax Library to speed up the performance of your web applications.  You can download the PDF here or read it below:

Building High Performance Web Applications

Tags:

Sky broadcasting on Windows Media Center

image

Great news for my UK peeps – Sky is now available on Windows Media Center.  For the longest time Sky has had a lot of great TV programming including the best football league in the world (Premier League :-) ) but you needed one of those pesky satellite dishes and boxes under your tv.  Well that is no more because they’re doing it over the internet now! No dish, no box just your PC. Lovely.

To celebrate the launch of Sky Player on Windows 7, Sky and Microsoft are offering non Sky TV customers three months of Sky Player for the price of two with any Windows 7 purchase. Customers who already have Windows 7 can subscribe to the offer via the Sky Player sign in page in Windows Media Center.

Check it out here: http://www.microsoft.com/uk/windows/skyplayer/

Enjoy.

image

Tags:

News on the ASP.NET Ajax Library Beta

The ASP.NET Ajax Library Beta was released today! The five big things I’m going to talk about in this post are:

  1. The ASP.NET Ajax Library is now in Beta
  2. Contributing the ASP.NET Ajax Library to the CodePlex Foundation
  3. Merging the Ajax Control Toolkit with the ASP.NET Ajax Library
  4. Plans to provide support for the ASP.NET Ajax Library
  5. ASP.NET Ajax Library features that provide:
    • Powerful developer libraries and tooling support
    • Performance – build high performance websites
    • Interoperability – use it with any server platform and alongside jQuery
    • Extensible – build on top of the library and inherit from controls like DataView

Since July last year the team has been cranking out new features in 6 previews, each with exciting innovations including powerful productivity benefits for developers, performance enhancements to make your website faster and making the library interoperable with multiple server platforms and other JavaScript libraries like jQuery.

 

Contributing the ASP.NET Ajax Library to the CodePlex Foundation

clip_image002

When it comes to the web, open source and licensing is important – see yesterday’s Open Web Foundation (OWF) announcement about Microsoft’s contributions in the Open Web. The ASP.NET Ajax Library is the first project to be contributed to the CodePlex Foundation and we are incredibly excited because it allows the project to take other contributions by the community and be driven by your feedback. The ASP.NET Ajax Library will be distributed under the New BSD license.

Merging the Ajax Control Toolkit with the ASP.NET Ajax Library

Before today, the Ajax Control Toolkit (ACT) was an impressively popular download from CodePlex.com with 25,000 downloads per week. ACT provides, and will continue to provide, loads of rich controls for ASP.NET Web Forms developers to add Ajax experiences to their web applications without the need to write client-side code. In ASP.NET Ajax Beta, we have converted 34 controls to pure client script, so now developers who write client-side code (including ASP.NET MVC, PHP and Ruby on Rail developers etc.) can use them in their web applications too. As a bonus we’ve also made it possible to instantiate the ACT controls as jQuery Plugins – part of the interoperability efforts we have been making. (More on that later.)

Here’s an example of instantiating a Watermark ACT control using the new syntax:

  1. <script src="../scripts/start.debug.js" type="text/javascript"></script>
  2. <script src="../scripts/extended/ExtendedControls.debug.js" type="text/javascript"></script>
  3.  
  4. <script type="text/javascript">
  5.  
  6.     Sys.require(Sys.components.watermark, function () {
  7.         Sys.create.watermark("#input1", "Enter something...");
  8.     });
  9.     
  10. </script>


Plans to provide support for the ASP.NET Ajax Library

Knowing that there is someone on the end of the phone to talk to about an issue is important to our developers. When the full version of the ASP.NET Ajax Library is released Microsoft will provide full product support. We already provide full support for jQuery and we will continue this going forward.

ASP.NET Ajax Library features

Power for developers

Performance

Interoperability

Extensibility


Useful Links

Here are some links that you will find useful:

Tags:

Launching the Windows Server 2008 R2 Developer Learning Centers

image

Today we launched the Windows Server 2008 R2 Learning Centers on Channel9 – congrats to the team!  There’s great content on there including labs, videos, presentations etc covering a wide range of topics from performance and efficiency to extensibility.

Learn deployment, scale and extensibility

As a web developer, there are some lessons that of particular interest to me that teach me how to deploy and scale my web application and make sure it’s running lightning quick.  All this is covered in the “Extensible Web Platform” lesson.

Give your native code apps an API just like web apps

Also, I often want to create APIs for my web applications that allow other developers to interact with it and help create a rich ecosystem of apps that add value on top of my platform (think Twitter).  We’ve already showed you how you can do this using REST APIs (check out the Web App Toolkit for REST Services).  The Extreme Web Services course shows you how you can now do the same for your native code applications built in C++ etc.

Need Scale? There’s an extension for that!

If you need ultimate scale for your web applications be sure to check out the free extension called Application Routing Request which allows administrators to optimize resource utilization for application servers to reduce management costs for Web server farms and shared hosting environments.  Check out the blog post from the product team and see how Inernap are using it today to cut costs whilst improving scale and reporting.

Tags:

Photos from inside a Microsoft data center

cnet have some awesome photos of our brand new data center in Chicago.  It’s a pretty impressive facility and on the ground floor accommodates 56 containers each filled with 1800 to 2500 servers ready to run your Windows Azure apps.

Inside a container

Air skates

They’ve also got an interview with the guys who run the place…

Hat tip to @adamse



Tags: