Archive

Author Archive

ADO.NET Dataservices

May 29th, 2009 Laurens 't Hardt No comments

ADO.NET Dataservices is a new way to open your data to the web. It’s especially usefull in combination with a Rich Internet Client Application, such as a silverlight application or an AJAX application.

Dataservices is an implementation of WCF but has some restrictions to it.

  • Dataservices makes use of the ATOM or the JSON format to transport the data, no other format is supported.
  • The data is transported over the HTTP or HTTPS protocol and no other protocol is supported.
  • Agarding to authentication you can´t use of the WCF authentication model. You are restricted to the standard authentication model ASP.NET offers you, Windows Authentication and Forms authentication.
  • Dataservices has a REST based interface implementation, witch means a request to the service can only be done using REST.

Getting started with Dataservices.

To get started with Dataservices you first need to define a datasource. This datasource needs to implement IQueryable<T> for the Dataservices to use it. Two commonly used framework that implement this interface are LINQ2SQL and the Entity Framework. For use with Dataservices it’s prefered to use the EntityFramework. The  IQueryable<T>makes it possible for Dataservices to query the data but to be able to update insert and delete data the datasource also has to implement the IUpdateAble<T> interface, wich is implemented by the Entity Framework and not by LINQ2SQL.

Now the datasource is created the Dataservice has to be created. There is a new template for adding the dataservice in Visual Studio 2008 SP1.

New Ado Service

New Ado Service

After this has been added the dataservice needs to be pointed to the datasource, below is a sample of that where a NorthwindDataService  is Created which is pointed to a NorthwindDataContext. In the example the security is also set to read for all entities in the InitializeService method. The security can be set per entity and per method.

public class NorthwindDataService : WebDataService<NorthwindDataContext> {
InitializeService(IWebDataServiceConfiguration config)
{
config.SetResourceContainerAccessRule
("*", ResourceContainerRights.AllRead);
}
}

Dataservices is queried by REST, this can be tested in a browser by calling the service. In the examples below it’s shown how to query the service. For this example the url of the service is ‘http://localhost:5555/Bookmarks.svc’.

The url below request for the model of the data.

‘http://localhost:5555/Bookmarks.svc$metadata’

Metadata

Metadata

To request a list of all the bookmarks put the url below in the browser. Here the ‘/Bookmarksrefers to the entityset Bookmarks.

‘http://localhost:5555/Bookmarks.svc/Bookmarks’

As is shown in the metadata the key of Bookmark is the Id property. Every entity needs a key property. To get just 1 bookmark with id 1 the following url can be used:
‘http://localhost:5555/Bookmarks.svc/Bookmarks(1)’

It’s also possible to get a list of entities based upon a filter. For example get all bookmarks with Tags Devdays. This is done by using keywords, which always begin with a ´$´, in the querystring.

‘http://localhost:5555/Bookmarks.svc/Bookmarks?$filter=Tags eq Devdays’

For Silverlight applications it’s possible to query dataservices using LINQ2Dataservices so you don’t have to create these url’s yourself buth you can just use LINQ to create queries.

Much more information about ADO.NET Dataservices can be found on MSDN.

Categories: DevDays09 Tags: , ,

Silverlight 3 Navigation

May 28th, 2009 Laurens 't Hardt No comments

This post is about the session called What’s new in Silverlight 3 given by Mike Taulty.

A major disadvantage of RIA, Rich Internet Application, is that the state is of an application can not be recovered after the browser has been closed.

In Silverlight 3 there’s a solution for this problem. In SL3 you are now able to create a SL page. This in combination with the Frame and navigation Source make it possible to navigate through the same application based on the url.

The first part of the url is the path to the page on which the Silverlight page is located, for example http://localhost/SLapp.html.

After this the part of the url for the navigation within the application can be placed. This part must be preceded by a ‘#’, for example http://localhost/SLapp.html#SearchPage.xaml.

From webapplications we also now the querystring in the url for passing parameters to a site, this is also implemented in silverlight in the same way. The previously used url can then be formatted as followed http://localhost/SLapp.html#SearchPage.xaml?title=silverlight

More information about page navigation can be found at Mike Taulty’s blog.

Categories: DevDays09 Tags: , ,

Silverlight 3 Out of browser

May 28th, 2009 Laurens 't Hardt No comments

This post is about the session called What’s new in Silverlight 3 given by Mike Taulty

In Silverlight 3 it is now possible to run the application as a standalone desktop application. To enable this functionality this must be enabled in the AppManifest.xml file of the application.

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
EntryPointAssembly="TaskList"
EntryPointType="TaskList.App">
<Deployment.Parts>
</Deployment.Parts>
<Deployment.ApplicationIdentity>
<ApplicationIdentity
ShortName="Task List"
Title="Offline Task List">
<ApplicationIdentity.Blurb>
Allows saving your tasks offline
</ApplicationIdentity.Blurb>
</ApplicationIdentity>
</Deployment.ApplicationIdentity>
</Deployment>

The user can now choose to install the application to the computer, on right mouse click the menu below is shown.

sp3_install_menu

Next the user can choose where the shortcuts to the application will be placed.

sl3_install_app

The application can now be run from out of the browser but still in the same secure sandbox. The application is automatically updated whenever a new version of the application is available from the website.

After the application is installed it’s very easy for the user to remove the application from the computer. When running the application under the right mouse menu the option to install the application is now replaced by the option to remove the application.

sp3_remove_menu

Because it’s now possible to run Silverlight applications from the desktop it’s now also become possible to run a Silverlight application without having a internet connection.

A nifty feature is now introduced to Silverlight 3 to adapt to this situation. It’s is now possible to detect whether an internet connection is available or not.

Through the method NetworkInterface.GetIsNetworkAvailable() it’s possible to see if an internet connection is available. Through the NetworkChange.NetworkAddressChanged event network changes can be detected when a user connect or disconnect from the internet.

Categories: DevDays09 Tags: , ,

Today is the D(ev)-days

May 28th, 2009 Laurens 't Hardt No comments

Today we’re going to the deydays in the hague.

Here we will be attending seminars about:

  • Azure Services Platform, Microsoft in the cloud.
  • C# 4.0, the future of the C# language.
  • Silverlight 3.0, the new version of the Silverlight framework
  • ASP.NET AJAX 4.0, the new AJAX framework by microsoft.
  • Parallel programming, the new way for using multiple cores in .NET 4.0.

We will keep you informed about these and other subjects of the devdays.

Categories: DevDays09 Tags: ,