Microsoft PDC 2009 site is now accepting registrations. PDC 2009 will run from 17th November to 19th November 2009 at Los Angeles Convention Center Los Angeles. Here is pricing information from PDC website.

image

I think in or around PDC 2009 we should see commercial launch of Azure, Visual Studio 2010, .NET Framework 4.0 and maybe even Oslo.

Tagged with:
 

Introduction

In this tutorial we will look at how ADO.NET Data Services can be used to create services which are consumed by ASP.NET client. We will use Adventure works Lite database as an example to demonstrate the concepts. Code for this article can be downloaded at the bottom of the article.

ADO.NET Data Services as the name says is a services layer between your application and an underlying data source. It uses REST principals to access and persist information to and from the data source. Services layer itself can be created very easily. Most of the work is done by  Visual Studio for you.

In this tutorial we will build an application for AdventureWorks Lite database. We will build a page which let’s a user browse through products. The reason for picking up AdventureWorks Lite as an example is so that we can work with a variety of data including images. If you do not have AdventureWorks Lite then you can download it here. For our application we will work with this data model

image

Creating Service

Creating a ADO.NET Data Service in Visual Studio is a no brainer. All we need to do is add a new item of type ADO.NET Data Service, give it an appropriate name and we are done.

image

Our ADO.NET Service will interact with some kind of data source and Entity Framework perfectly fits that purpose. We now need to create a EDM (Entity Data Model) which includes tables we want to interact with via our services. If you never worked with Entity Framework then this quickstart will get you going.

By creating a service and our Entity Data Model we have put together two major components of our solution. Before we can hit F5 to see our service running, there are few things we need to put in place. We must tell our service that there is a Data Layer that we want it to use. Now all ADO.NET Data Services inherit from DataService<T> which can be found in System.Data.Services namespace. The code produced by Visual Studio for our service leaves a placeholder for <T> with a comment. All we need to do is specify the correct type. Our class declaration for our service should look like this.

public class AdventureWorksService : DataService<AdventureWorksEntities>

Here we have established integration between our service and our data source. Next thing we need to do is configure appropriate access levels for our service and its operations. Code below when executed initializes our service to have all possible access over all entities defined in our EDM and all access over all operations. Note the asterix, basically we are saying here that include all Entity Sets and all operations.

public static void InitializeService(IDataServiceConfiguration config)
{
  config.SetEntitySetAccessRule("*", EntitySetRights.All);
  config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
}

We are now ready to go and hit F5. If we set AdventureWorksService.svc as a start page and run our project we can see our service running. Now that we have our service running, we will start building our ASP.NET pages which will query our service, receive and display data.

image

Creating Proxy Objects

Our ASP.NET application will need to access the service through a proxy. Creating a proxy is very easy. After making sure that our service is running, we need to add a service reference to our serivce. This can be done this way.

image

It is also a good idea to change the Namespace from ServiceReference1 to AdventureWorksService.

Creating Web Page To Display Data

We can now make calls to our service and retrieve data. First thing we need to do is load data from ProductCategory and bind it to a dropdown. But before that let’s have a look at what we will produce.

image

Getting back to binding our dropdown control. We should write a query which calls our service which in turns fetches data from database and delivers to us. One good thing about ADO.NET Data Services is that you can write LINQ queries with it. ADO.NET Data Services comes with a LINQ provider popularly known as LINQ To REST.  Without LINQ support ADO.NET Data Services will be just too complicated and IMO useless. However LINQ support is limited. Here are things you cannot do:

  1. You cannot write queries which involve joins or sub queries.
  2. You cannot create anonymous types in your queries.
  3. Aggregates such as Count, Min, Max are not available.
  4. There is no GroupBy support available.

Besides the list of can’t do above, LINQ To REST still makes working with ADO.NET Data Services much easier than otherwise. Following code will make a service call and bind our drop down.

private void BindProductCategories()
{
  DataServiceQuery<ProductCategory> productCategories =
    context.CreateQuery<ProductCategory>("/ProductCategory");

  var query = from p in productCategories
    orderby p.Name
    select p;

  ddlProductCategory.DataSource = query;
  ddlProductCategory.DataBind();
}

We’d also like to refresh data in our grid when the user selects another category. This is done by BindProductsGrid method.

private void BindProductsGrid()
{
  int productCategoryID = Convert.ToInt32(ddlProductCategory.SelectedValue);

  DataServiceQuery<Product> products =
    context.CreateQuery<Product>("/Product");

  var query = from p in products
    where p.ProductCategory.ProductCategoryID == productCategoryID
    select p;

  gdvProducts.DataSource = query;
  gdvProducts.DataBind();
}

The way I bind the image is by using another page which just does Response.BinaryWrite.  Here is the markup of default.aspx page which is the entire UI. You can play with it by downloading the entire solution. The markup is here just to make the post look good ;)

<form id="form1" runat="server">
  <div>
    <div>
      Product Category
      <asp:DropDownList ID="ddlProductCategory" runat="server"
        DataValueField="ProductCategoryID"
        AutoPostBack="true"
        DataTextField="Name"
        OnSelectedIndexChanged="ddlProductCategory_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    <br />
    Products
    <br />
    <div>
      <asp:GridView ID="gdvProducts" runat="server"
        CssClass="sample"
        Width="600px"
        AutoGenerateColumns="false"
        OnRowCreated="gdvProducts_RowCreated">
        <Columns>
          <asp:BoundField DataField="ProductNumber" HeaderText="Number" />
          <asp:BoundField DataField="Name" HeaderText="Name" />
          <asp:TemplateField>
            <ItemTemplate>
              <asp:Image ID="Image1" runat="server" ImageUrl='ImageHelper.aspx' />
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
    </div>
  </div>
</form>

Conclusion

This was a brief introduction to ADO.NET Data Services. We looked at how to create a service and consume it in a ASP.NET website. We also looked at some limitations of LINQ provider used by ADO.NET Data Services. In future posts I will talk about other features of ADO.NET Data Services.

Download Code For This Article

ADONETDataServices Sample Code Size 84.72 KB

Tagged with:
 

I’ve been using Bing as my main search engine for sometime and I’m very happy with it. Within that plain search box lies a lot of power and many ways to search for information. Here I am sharing some of the ways I use Bing on daily bases. You may find these interesting and see that there is more to Bing than just plain old web search.

1. Search For Weather

Just type in the city name followed by forecast

sydney forecast

image

2. Get Search Results returned in RSS format

Bing can return your results in RSS format. In this example I am searching for “Best Search Engine” and I want my results in RSS format. I can then subscribe to the feed in my feed reader and keep an eye on when search results are updated.

http://www.bing.com/search?q=best+search+engine&format=rss

 image

3. Search Within A Website

With Bing you can search for content on a particular website. For example here I am searching for “Silverilght” on One .NET Way.

site:thereforesystems.com silverlight

image

4. Exclude a website from your search

Following search for Silverlight will exclude results from One .NET Way

-site:thereforesystems.com silverlight

image

5. Celebrity Search

Bing has a feature called xRank which keeps track of search volume on celebrities. You can also compare Bing popularity of celebrities. Here I am comparing popularity of Michael Jackson with Jet Li. xRank can be accessed at http://www.Bing.com/xRank

image

6. Bing Without Background Image

Bing home page by default displays a background image. Here is a sample:

image

If you don’t want to see the background (and why not?), you can turn it off by going to this address.

http://www.bing.com/?rb=0

image

7. Search Where results lead to File Type

A site can be searched for all links which further have links to specified file type. For example here I am searching Codeplex and I’d like to see results where I can find pdf files.

codeplex contains:pdf

8. Search For Flight Information

Bing also returns real-time flight information. Following text when typed into Bing search box return information for United flight 660

flight info united 660

image

9. Search within a country

You can specify a location for your search. Here I am searching for Bill Gates and I want search results from India.

Bill Gates loc:IN

image

10. Use Bing as a Dictionary

You can definition of any word by simply typing define and then the word. Example

define cyberspace

 image

Tagged with:
 

image

As a web developer it is hard to ignore the popularity of JQuery. The issue however is that there are too many JQuery plugins available and at times it is hard to decide which one to chose. The Ultimate JQuery List is a fantastic web site which lists hundreds of JQuery plugins with examples.

This will serve as a great reference point if you are looking for JQuery examples.

Tagged with:
 

 imageMuch awaited Windows 7 went RTM today. Microsoft’s new Operating System is scheduled to be available to available to public around October 22. MSDN and TechNet subscribers will be able to download Windows 7 in next few weeks, most likely around August 6. Comparing to release of Vista this looks much more well executed. Windows 7 has received more positive press than any other OS by Microsoft. This in my opinion is how expectations were managed. Rather than coming out with hyped up features which never made it to the product (read WinFS) Windows 7 managed communication to the best.

I’m starting the countdown to when I can download Windows 7.

You can read more about it on Microsoft Press Pass site.

Tagged with:
 

Jim Nakashima has announced the availability of Windows Azure Tools and SDK July 2009 CTP. Here are the download links:

 

Here is a list of new goodies in July 2009 CTP re-posted from this link

New for the July 2009 CTP:

  • Support for developing and deploying services containing multiple web and worker roles. A service may contain zero or more web roles and zero or more worker roles with a minimum of one role of either type.
  • New project creation dialog that supports creating Cloud Services with multiple web and worker roles.
  • Ability to associate any ASP.NET Web Application project in a Cloud Service solution as a Web Role
  • Support for building Cloud Services from TFS Build
  • Enhanced robustness and stability

Windows Azure Tools for Microsoft Visual Studio includes:

  • C# and VB Project Templates for creating a Cloud Service solution
  • Tools to change the Service Role configuration
  • Integrated local development via the Development Fabric and Development Storage services
  • Debugging Cloud Service Roles running in the Development Fabric
  • Building and packaging of Cloud Service Packages
  • Browsing to the Azure Services Developer Portal
  • SSL Certificate selection

 

On my machine I uninstalled the old CTP and installed July 2009 CTP. All is working well and no smoke came out of my laptop.

Tagged with:
 

One of the things that you will notice when you open an Office 2010 application is that the orb has a new look. This is what the orb looks like in Word 2007

image

This look has slightly changed now. Here is the orb in Word 2010

image

The look has also changed when you click on the orb. Here is a comparison. This is what we see in Word 2007. You are also able to see  your current document in background.

image

In Word 2010, current document is hidden.

image

But that’s not all, there are more features available here. For example when you click on Print you immediately see a preview.

image

Tagged with:
 

Microsoft is interested in feedback from those who have access to Office 2010 Technical Preview. And they are asking for it in a nice way. When you install the Technical Preview, you will notice two icons in your Icon Tray.

image

Don’t they look cute? As you can see that there is a smile icon and a frown icon. If you are happy about something then click on the smile icon which opens up a form where you can put in your comments and send them to Microsoft with a screenshot of the Office Application from your machine.

Office 2010

And similarly if you don’t like something then you can send them a frown.

Office 2010

I think this is nice and clever little way to get feedback. It sure does convey the “We care” message.

Tagged with:
 

Because of my karma and auspicious planetary alignments I got an email yesterday notifying me that I can access Technical Preview of Office 2010. Needless to say that I downloaded a 32bit edition immediately. This is a teaser post with screenshots of Office 2010 setup on Windows XP. Enjoy.

image

Oops

image

image

 

image

 

image

 

image

 

image

As you can see that not much has changed for Office setup and this is good. I have found Microsoft Office setup process to be the most stable.

Tagged with:
 

Within our Silverlight application if we want to know the URI where our Silverlight content is running, we can tap into System.Windows.Browser namespace. This namespace contains object which are full of Browser related information. This is an example of retrieving the URI from within Silverlight application.

<StackPanel x:Name="LayoutRoot" Margin="10">
  <TextBlock Text="Your URL is: " />
  <TextBlock Text="{Binding AbsoluteUri}" />
</StackPanel>

 

In our C# code we can set the DataContext so that the second TextBlock above displays the information we desire.

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
  LayoutRoot.DataContext =
    System.Windows.Browser.HtmlPage.Document.DocumentUri;
}

 

Here is my output which displays the URL at which my Silverlight plugin is hosted.

image

Tagged with:
 

Silverlight 3 among its other features includes element to element binding. This was always available in WPF but somehow missing in Silverlight 1 and 2. And now Silverlight 3 has bridged that gap. Element to element binding can reduce code when used properly. In this post I will show you how to use this feature.

Example

In this very basic example I will use two controls, a TextBlock and a Slider. When the slider is moved, the value in TextBlock changes accordingly.

<StackPanel x:Name="LayoutRoot">
  <TextBlock
    Width="100"
    Foreground="Blue"
    HorizontalAlignment="Center"
    Text="{Binding Value, ElementName=slider1}" />
  <Slider
    x:Name="slider1"
    Minimum="0"
    Maximum="100"
    Width="200" />
</StackPanel>

 

Here is a screenshot of the output produced by XAML above.

Element Binding 

Element binding can come in very handy in certain scenarios. An example can be making all fields read-only based on a status flag. Rather than writing C# code, this can be done easily and cleanly with element binding.

Tagged with:
 

Microsoft has released Silverlight 3. Nuff said! Go and get it here.

image

Tagged with: