The i-Technology Media!
Register | Log in
   
 
.NET  ·  AJAX  ·  CLOUD  ·  ECLIPSE  ·  FLEX  ·  OPEN WEB  ·  iPHONE  ·  JAVA  ·  LINUX  ·  OPEN SOURCE  ·  ORACLE  ·  PBDJ  ·  SEARCH  ·  SILVERLIGHT  ·  SOA  ·  VIRTUALIZATION  ·  WEB 2.0  ·  WIRELESS  ·  XML
Comments
Drool, Britannia? Is the UK Failing the Cloud?
By Roger Strukhoff
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.
Jan. 8, 2012 11:38 AM EST
read more & respond »
Cloud Expo on Google News
Did you read today's front page stories & breaking news?

Cloud Expo & Virtualization 2011 West
Keynotes
Oracle
Opening Keynote | An Enterprise Cloud for Business-Critical Applications
Abiquo
Day 2 Keynote | The Enterprise Cloud Tightrope - Balancing for Success
Akamai
Day 3 Keynote | The DNA of an Enterprise Cloud
DIAMOND SPONSOR:
Oracle
Many Clouds, Many Choices'Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Enterprise Cloud Best Practices - Town Hall - Join the discussion…
PLATINUM SPONSORS:
Intel
Progressing Toward the Federated, Automated and Client-Aware Cloud
New Relic
How to build an app with Twitter-like throughput
Rackspace
Computing in the Cloud Era
GOLD SPONSORS:
Gale Technologies
Practical Cloud Migration
IBM
Re-think IT. Re-inventing Business.
Intel/McAfee
Identity Driven Security in the Cloud
PerspecSys
Hackers Hackers Everywhere, Is My Public Cloud That Safe?
Red Hat
Unlock the Value of the Cloud
SHI
Mission Critical Applications and the Cloud - Myth or Reality?
SoftLayer
Not Your Grandpa's Cloud
Terremark
Integrating Enterprise Clouds
VMware
Upgrade to a vCloud
POWER PANELS:
Cloud Expo Silicon Valley: CTO Power Panel
Cloud Expo Silicon Valley: CEO Power Panel
Cloud Expo Silicon Valley: Cloud SuperStars Panel
Cloud Expo Silicon Valley: CloudNOW Panel
Click For 2010 West
Event Webcasts
Cloud Expo & Virtualization 2011 East
DIAMOND SPONSOR:
Dell
Dell & VMware Deliver the Enterprise Hybrid Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Are Financial Services Organizations Risking Security by Avoiding Cloud Computing?
Oracle
From Consolidation to Enterprise Private PaaS
PLATINUM SPONSORS:
Intel
Driving the Transformation to Next Generation Cloud Data Centers
Rackspace
The Inevitability of an Open Cloud
GOLD SPONSORS:
CA Technologies
Follow YOUR path to Cloud Computing
Interxion
Who Keeps the Cloud in the Air?
Microsoft
Patterns for Cloud Computing
PerspecSys
War in the Clouds: Are you ready?
ServiceMesh
The Big Win: Stop Playing Small-Ball with Your Cloud Strategy
Terremark
Evaluating Enterprise Clouds
Xiotech
Cloud Storage: Myths and Realities
POWER PANELS:
Cloud Expo New York: CTO Power Panel
Cloud Expo New York: CEO Power Panel
Cloud Expo New York: CMO Power Panel
Cloud Expo New York: Wrap-Up Power Panel
Click For 2010 West
Event Webcasts
Live Google News by SYS-CON!
Top Three Links You Must Click On


From the Blogosphere
RIA Services: A DomainService Is a WCF Service – Add Service Reference
Everything you know about a WCF service should be true of a DomainService

By: Brad Abrams
Nov. 23, 2009 10:30 AM

RIA Developer's Journal

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

You need:

  • Visual Studio 2010 Beta 2 (this actually works exactly the same in VS2008 and the corresponding RIA Services drop)
  • Silverlight 4 Beta

You can download the completed solution as well. and be sure to check out the full talk.

1. Getting to the Service

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:

http://[hostname]/[namespacename]-[classname].svc

so in my case that is:

http://localhost:30335/Services/MyApp-Web-DishViewDomainService.svc

Hitting that URL in the browser gives you the very familiar WCF proxy help screen:

image

And tacking on the ?wsdl gives you the WSDL for this service

http://localhost:30335/Services/MyApp-Web-DishViewDomainService.svc?wsdl

 

image

 

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)…

image

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.

  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. var context = new DishViewDomainServiceClient("BasicHttpBinding_DishViewDomainService");
  4. var plates = context.GetPlates(4);
  5. this.dataGridView1.DataSource = plates.RootResults;
  6. foreach (DataGridViewRow row in dataGridView1.Rows)
  7. {
  8. PlatesListOriginals.Add(ToPlate(row));
  9. }
  10. dataGridView1.CellEndEdit += dataGridView1_CellEndEdit;
  11. dataGridView1.SelectionChanged += dataGridView1_SelectionChanged;
  12. }

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:

  1. <endpoint address="http://localhost:30335/Services/MyApp-Web-DishViewDomainService.svc/soap"
  2. binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DishViewDomainService"
  3. contract="ServiceReference1.DishViewDomainService" name="BasicHttpBinding_DishViewDomainService" />
  4. <endpoint address="http://localhost:30335/Services/MyApp-Web-DishViewDomainService.svc/binary"
  5. binding="customBinding" bindingConfiguration="BinaryHttpBinding_DishViewDomainService"
  6. contract="ServiceReference1.DishViewDomainService" name="BinaryHttpBinding_DishViewDomainService" />

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…

  1. void dataGridView1_SelectionChanged(object sender, EventArgs e)
  2. {
  3. Plate currentPlate = ToPlate(dataGridView1.CurrentRow);
  4. this.pictureBox1.ImageLocation = "http://hanselman.com/abrams/Images/Plates/" + currentPlate.ImagePath;
  5. }

Be patient with this one… sometimes it takes a while load a picture.  it is using hanselman’s server which gets slammed sometimes ;-)

image

Now we have our data, we can scroll through it and view the pretty pictures.

 

3. Updating the Data

 

 

 

But how do we update the data… well, let’s take a look at CellEditEnd event handler…

  1. void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2. {
  3. var context = new DishViewDomainServiceClient("BasicHttpBinding_DishViewDomainService");
  4. Plate currentPlate = ToPlate(dataGridView1.Rows[e.RowIndex]);
  5. ChangeSetEntry[] changeSet = new[] {
  6. new ChangeSetEntry{
  7. OriginalEntity = PlatesListOriginals[e.RowIndex],
  8. Entity = currentPlate,
  9. Operation = DomainOperation.Update
  10. }
  11. };
  12. context.SubmitChanges(changeSet);
  13. }

 

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.

image

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.

Read the original blog entry...

Published Nov. 23, 2009— Reads 6,175
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
Related Stories
▪ Is Everything I Know About Crowdsourcing Wrong?
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:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers

ADS BY GOOGLE

Breaking Java News
Teamsters' Drive Up Standards Bus Campaign Reaches Milestone 300th Win
Chrysler Group's 'It's Halftime in America' Super Bowl Video Earns Second Place in YouTube's Ad Blitz 2012 Contest
U.S. Census Bureau Daily Feature for February 18
U.S. Census Bureau Black History Month Feature for February 18
Following Is a Test Release
President of the Independent Libya Foundation Announces Vision Statement for Libya on the Anniversary of the Libyan Revolution

ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPENWEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2
Apache   |   CMS   |   CRM   |   HP   |   Oracle Journal   |   Perl   |   Python   |   Red Hat   |   Ruby on Rails   |   SAP   |   SaaS

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS:   |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  Cloud Computing Conference & Expo  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.
 
close this window