Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud.
We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
I made the fairly bold statement at my PDC09 talk that a DomainService IS A WCF Service. That is, everything you know about a WCF service should be true of a DomainService. I didn’t have time to get into this in my talk, so I thought I’d hit the highlights here. And in the process show how to consume a DomainService from a WinForms. You can also see more examples at: http://code.msdn.microsoft.com/RiaServices
The first thing we need to do is get at the data underlying service. In the mainstream Silverlight case this is all handled for you by the implicit link between the Silverlight client and the ASP.NET server. However, in the vanilla WCF case, you get the full control. The URL to the service is of the following format:
The rest is easy for anyone halfway familiar with WCF… Create a new WinForms project and select Add Service Reference. Enter the URL (note discover doesn’t work for this sort of service yet)…
The you have a service!
2. Querying for the Data
Now, we have a service, let’s look at actually getting data out of it. In this case I already have a WinForms DataGridView on my form. So getting data into it should be no problem.
In line 3, we create a new instance of the web service client and point it at the right binding. The service exposes a couple of different bindings as you can see in the app.config file for the WinForms app:
In line 4, we call the service to get our list of Plates… in this case we are doing things synchronously.. you could of course do it async if you’d like.
In line 5, we bind the DataGridView to the results of this call.
In lines 6-9, we are saving off the “original” values.. for each item we got.. this will help us when we do updates.
In line 10, we handle the cell edit event, we will come back to look at that later.
in line 11, we sign up for the selection changed event so we can initialize the picture…
In line 3, we are creating a new context. we could be sharing with the load method, but I thought this would be cleaner to follow.
In line 4, we save off the currently selected plate.
In lines 5-10 we are building up a changeset to send to the server.
Notice we need to give it the original values we saved off in the load method. Getting the original values right is the likely the hardest part here. Keep in mind that assignment in C# (and VB) is by default by reference. So you can’t just store off a reference, you must actually make a copy of the original values.
Then in line 12, we submit the changes.
Make a change, tab off it.. This will call the server and post your update. Re run the app to see that it took.
Notice here we are sending one item in the change set. You could of course build up a change set on the client with many entries and then send them as a batch.
I hope that helps to make it clear how a DomainService IS A WCF Service… You can download the completed solution as well. and be sure to check out the full talk.
About Brad Abrams Brad Abrams is currently the Group Program Manager for the UI Framework and Services team at Microsoft which is responsible for delivering the developer platform that spans both client and web based applications, as well as the common services that are available to all applications. Specific technologies owned by this team include ASP.NET, Atlas and Windows Forms. He was a founding member of both the Common Language Runtime, and .NET Framework teams.
Brad has been designing parts of the .NET Framework since 1998 when he started his framework design career building the BCL (Base Class Library) that ships as a core part of the .NET Framework. He was also the lead editor on the Common Language Specification (CLS), the .NET Framework Design Guidelines, the libraries in the ECMA\ISO CLI Standard, and has been deeply involved with the WinFX and Windows Vista efforts from their beginning.
He co-authored Programming in the .NET Environment, and was editor on .NET Framework Standard Library Annotated Reference Vol 1 and Vol 2 and the Framework Design Guidelines.
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice: