Archive | WCF RIA Services RSS feed for this section

Slides fra talk om WCF RIA Services hos Dansk IT

1 Dec

Jeg afholdte i formiddags en 3-timers talk om WCF RIA Services hos Dansk IT. Der var en virkelig god dialog og der kom nogle gode (og afklarende) spørgsmål.

Slides og demoer (inklusive custom validation) kan downloades her:
http://dl.dropbox.com/u/4243120/events/20101201-danskit.zip

by xamlgeek
@thomasmartinsen

Use DomainServices as Service References

30 Nov

DomainServices was introduces as part of WCF RIA Services. WCF RIA Services offers a solution on how we can build a middle-tier having clients and servers.

Using a DomainService in a Silverlight client is very easy using WCF RIA Services – the WCF RIA Services link between the client and the server will automatically generate the client side code that we need to communicate with the server.

2010-11-30_161311

To avoid writing middle-tier functionality more than once we want to be able to reuse the DomainService and the logic inside of it to all of our projects. Most project types beside Silverlight do not understand WCF RIA Services yet. But as a DomainService ultimately just is a WCF Service we can just make a normal Service Reference (or ChannelFactory) to it and reuse the logic.

For that to work you need to make a few adjustments to the project hosting the service. When you add a DomainService to your project a DomainServiceHttpModule http module is added to your web.config and ASP.NET compatibility is turned on.

2010-11-30_163517

The DomainServiceHttpModule dynamically generates a WCF Service based on our DomainService. In this sample I have added a DomainService called DomainService1 in the root of my ASP.NET web project called WebApplication1. The web project is using port 6479. Based on this information I can point to my dynamically generated WCF Service from my browser:

http://localhost:6479/Services/WebApplication1-DomainService1.svc

2010-11-30_172225

If I try to make a Service Reference to the WCF Service I will get an error:

There was no endpoint listening at http://localhost:6479/Services/WebApplication1-DomainService1.svc that could accept the message.

Before I can make a Service Reference to the service I need to define an endpoint in the web.config. First I need to add a custom configuration section for DomainServices within System.ServiceModel.

2010-11-30_200119

Using the RIA Services Toolkit I can now define a SOAP endpoint (I need to add a reference to Microsoft.ServiceModel.DomainServices.Hosting found in the Microsoft SDKs/RIA Services/v1.0/Toolkit/Libraries folder).

2010-11-30_200643

Finally I can add a Service Reference to the service and use it as if it was a regular WCF Service.

2010-11-30_200816

2010-11-30_200917

You can download the full sample from http://bit.ly/dOVMVR.

by xamlgeek
@thomasmartinsen

Execute Stored Procedure in WCF RIA Services

5 May

WCF RIA Services amazing! I use it in a several Silverlight projects and keep getting amazed.

Today I got a question about retrieving data from a Stored Procedure in Silverlight using WCF RIA Services and a LINQ-to-SQL datamodel.

The LINQ-to-SQL datamodel in this sample contains a table called Book and a stored procedure called GetBooks. The stored procedure returns a list of books from the Book table and it is attached to the datamodel.

image

I have created a domain service that use the datamodel to return data to the Silverlight client. In the service I have created a method called GetBooks – it returns an ObservableCollection of Books.

image

The stored procedure return an ISingleResult of GetBooksResult. I have tried to convert the result to an ObservableCollection without success (any ideas?). To fix this issue I loop the result and add the items to a new ObservableCollection.

Finally, on the Silverlight I call my domain service (_context) and invoke the GetBooksQuery method to get the result.

image

I got inspiration from this blog post by Scott Gu.

by xamlgeek
twitter.com/thomasmartinsen

Properties in WCF RIA Services – using LINQ-to-SQL

28 Feb

I have previously written a post about including properties in WCF RIA Services. The post was using POCO as business model. If you use LINQ-to-SQL as your business model you might need some extra load options to get your associated properties sent from the server to the client.

You can add the extra load options in the domain service methods on the server. In my previous post I use two entities; a Company and an Employee entity. The Company entity has a Employee property called CEO.

First you need to add a reference to System.Data.Linq and add a using in the BusinessService.

image

Second you need to add the load options. In this case you want CEO to be loaded when the Company is loaded.

image

Finally you set the load options to the DataContext and then you’re ready to return your data as normal.

image

(In the code above I get an error on the DataContext; don’t mind that – it’s just because I used the sample code from the previous post that don’t use LINQ-to-SQL and there don’t recognize the DataContext object.)

by xamlgeek

Include related properties in WCF RIA Services

21 Feb

WCF RIA Services provide lots of possibilities on getting data from the server to the client whether it is a Silverlight client or a console application.

One of the challenges that you may experience using WCF RIA Services is getting related properties to an entity to be included on the client. But no need to get scared – it is actually pretty easy.

First of all you need to create an association between your entity and the related entity. Lets say we have a company (Company) with a CEO (Employee):

image

image

When we get a list of companies from the client we would like to have the CEO property included and filled on the company. To do that we need to add a few attributes to the CEO property. Instead of adding the attributes on the entity object we can create a metadata file that holds this type of information.

image 

Now the CEO property will be included, filled and ready to use when we call a query from the client that returns a list of companies.

You can download sample from my DropBox: http://dl.dropbox.com/u/4243120/SL%20Demos/RiaIncludePropertiesDemo.zip

by xamlgeek

Talk about RIA Services

18 Nov

This afternoon I did a talk about .NET RIA Services and about building data-driven applications with ASP.NET and Silverlight.

You can get the slides and demos here:

At the same time on the other side of the world, the keynote on day 2 at PDC09 was taking place. At the keynote Scott Guthrie presented Silverlight 4 beta including WCF RIA Services beta.

WCF RIA Services does not require Silverlight 4 beta – it is targeted Silverlight 3 development.

You can read a lot more about WCF RIA Services here where you also can get the bits, watch videos, get samples and of course get the documentation.

I’m really looking forward to get into the details of the WCF RIA Services beta (and of course of Silverlight 4 beta) – and I will keep you posted ;)

by xamlgeek

Silverlight, Prism & .NET RIA Services

13 Nov

In these days I’m working on a project for a Danish media company. The project is pilot showing the possibilities with the FAST search engine. On top of the FAST search engine we are building a Silverlight client showing the result. From here the user and dive deeper into the results or work with results.

To make the Silverlight client as modular and flexible as possible I have used PRISM to split the content into modules and the eventaggregator inside PRISM to make the modules disconnected from eachother and selfcontained.

I have implemented .NET RIA Services as middle tier to transfer the search result from the FAST search engine to the Silverlight client. Even though .NET RIA Services works great and seems really stable, there are some bugs and missing features. I’m looking forward to the official beta of .NET RIA Services next week :)

All-in-all I was a bit exited about this setup and if it worked. Even though I’m not through with the project, the technologies seems to work great together. I’m not sure that I can post deeper technical stuff about this project, but maybe some fragments will be available.

Next week (18th December 2009) I’m hosting a talk about .NET RIA Services – more about that here.

by xamlgeek

Follow

Get every new post delivered to your Inbox.

Join 1,356 other followers