Archive for September, 2008

One of my favorite features in Visual Studio is Snippets. I find them very useful when trying to code something really really fast. Till now I had to write them all by hand and then import them on VS, well not any more.

Matthew has released a first version of the Snippet Designer. In it you’ll find:

  • A Snippet Editor hosted in the IDE which lets you edit the code, make replacements and change snippet properties
  • A Snippet Explorer which lets you search for Snippet files on your computer an quickly open and edit them.
  • A context menu item inside of the VB, C# and XML editor that lets you export any highlighted code into the snippet editor

You can find more information about it in Mathew’s blog

I’m pretty often asked the question “Can I use real (as in coming from a database) data in my Silverlight application?” the answer is “of course”, although this requires a lit more work than any other technology (WinForms, ASP.NET, WPF) you could use. The reason for that is, that as you probably already know, Silverlight runs on the client, so you’ll need a way to move the data from the server to the Silverlight Client application.

There are a number of ways you can achieve that, like for example building a WCF Service and the necessary DTOs (Data Transfer Objects) to communicate between Silverlight and your Business Layer. There is though, a far more easiest way to achieve that functionality and that is using .

For those that haven’t heard about ADO.NET Data Services before, ADO.NET Data Services is a new part of the .NET 3.5 framework that supports exposing a data model (e.g. LINQ for SQL, Entity Framework, etc.) as a set of queryable REST endpoints. ADO.NET Data Services maps the four data verbs into the four HTTP verbs POST (Create), GET (Read), PUT (Update), DELETE (Delete).

Essentially it provides a way to use a data model across the firewall. It works by exposing IQueryable endpoints through a URI-based syntax allowing developers control over how the data is retrieved. In addition ADO.NET Data Services utilizes JSON and Atom as the serialization formats. These make it easy to consume in client-side interfaces like Silverlight and AJAX.

In order to use ADO.NET Data Services you’ll first have to create a Data Model. You can either use a Linq To SQL (it currently supports only read – you’ll have to implement updates) or an Entity Framework model. Once your data model is ready you can create a new Data Service in your Silverlight Web Site (Note: the data service won’t work if it’s implemented in a different domain than the one running the Silverlight application. Cross domain calls are disabled due to IE security) by right clicking on your project and selecting “add new ADO.NET Data Service”. Once the service is created you’ll have to specify the model type in the service code behind as well as the permissions the service will have on the data.

public class WebDataService : DataService< /* TODO: put your data source class name here */ >
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(IDataServiceConfiguration config)
        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:
        // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
        // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);

The next step is to create the service proxy classes in your Silverlight project. You can do that either by adding a service reference to your Silverlight application project or by using the DataSvcUtil.exe tool located in the C:WindowsMicrosoft.NETFrameworkv3.5 directory to create them and then copy them to your project. Typically you would call it by specifying the URI of the service, the name of the class file to create and what language to use:

DataSvcUtil.exe /uri:http://localhost:1025/YourService.svc

You will also need to add a reference to the System.Data.Client.Services.dll assembly. This is the ADO.NET Data Services client library that allows asynchronous LINQ queries that are translated into the URI syntax automatically. Note that if you’ve installed Visual Studio 2008 SP1 this library is no longer compatible with ADO.NET Data Services and you’ll not be able to connect to your service. (read more about this here). Fortunately the guys in Microsoft have released an interim version of this assembly that works with Silverlight Beta 2 until Silverlight releases its next version. You can download this assembly from Mike Flasko’s blog.

The way you work with the referenced service is similar to the way you would normally work with an Entity Frameworrk Data model. You first instantiate a Data Context specifying the service URI and then you create a Linq query to fetch the data. Now normally, you could execute the query directly by calling something like ToList() against the query, that isn’t supported in Silverlight 2 Beta 2 though.  In fact, if you try you will simply get a NotImplemented exception. In order to execute these queries, you will need to cast the query into a DataServiceQuery.  The DataServiceQuery allows you to call BeginExecute to start an asynchronous query as seen below:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
  NorthwindEntities ctx = 
    new NorthwindEntities(new Uri("/Products.svc", UriKind.Relative));
  var qry = from p in ctx.Products
             orderby p.ProductName
             select p;
  // Cast the query to a DataServiceQuery
  DataServiceQuery<Product> productQuery = 
  // Start the execution
  productQuery.BeginExecute(new AsyncCallback(OnLoadComplete), 
void OnLoadComplete(IAsyncResult result)
  // Get a reference to the Query
  DataServiceQuery<Product> productQuery = 
  // Get ther esults and add them to the collection
  List<Product> products = productQuery.EndExecute(result).ToList();

Once the query completes, it will call the OnLoadComplete method that was specified in the AsyncCallback.  In this method, you first grab the DataServiceQuery that you sent with the request then end the execution to retrieve the results.

While its not as straightforward as synchronous execution, the new ADO.NET Data Services certainly works well in Silverlight 2 Beta 2 and provides a great way to use existing or planned data models over Internet applications.

One of the great advantages offered by Entity Framework compared to Linq to SQL is the fact that it is designed to support any database not just MS SQL. All you need to have in order to connect to third party databases is the right ADO.NET provider.

Unfortunately till recently there were no implementations of such providers. Devart (formerly Core Lab) though, has released a new version of their ADO.NET providers, which includes support for the Entity Framework.

So with DevArt’s new ADO.NET providers you’ll be able to connect to Oracle, MySQL, and Postgress using Entity Framework.

I have needed to implement URL rewriting in a lot of projects I was involved with in the past and have chosen various solutions for each, from building my own solution till using open source modules such us UrlRewriting.Net.

If your web project is going to be hosted on IIS 7 though, then I would highly recommend using the IIS URL Rewrite Module.

The Microsoft URL Rewrite Module for IIS 7.0 provides flexible rules-based rewrite engine that can be used to perform broad spectrum of URL manipulation tasks, including, but not limited to:

  • Enabling user friendly and search engine friendly URL with dynamic web applications;
  • Rewriting URL’s based on HTTP headers and server variables;
  • Web site content handling;
  • Controlling access to web site content.

Protected: Windows live messenger translation bot

Categories: Web
Enter your password to view comments.

This content is password protected. To view it please enter your password below:

chrome1Just a few days after Microsoft released IE8 Goggle retaliated by releasing their browser, Chrome. After installing it my first impressions are:

  • Extremely clean and streamlined UI
  • Nice source view and developer helpers
  • Nice download manager
  • Extremely fast page loading
  • Great JavaScript performance

What’s missing (in my opinion):

  • Grouped tab browsing
  • Web Slices
  • Accelerators

To conclude, I thing IE8 is a more feature complete browser according to my standards and although it’s beta has more rendering problems than chrome has at the moment, I’m sticking to IE as my default browser.

UPDATE: It doesn’t support Silverlight arghhh!!!