 |
|
 |
|
|
I'm Out and About |
|
Andy's Blog
|
By Andy Beaulieu on
5/28/2008 6:23 PM
|
|
|
|
I'll be doing a few Silverlight talks in the coming weeks - if you are in the area, stop by and say hi!
Tuesday, June 3rd - Friday, June 6th I'll be at Tech-Ed Developers in Orlando leading the Instructor-Led Lab "Microsoft Silverlight 2 Foundations" on 6/3 and 6/5, and also milling about as a Technical Learning Guide throughout the week.
Saturday, June 7th 10:20am - 11:30am I'll be presenting "Silverlight 2 for Data Applications" at the ]inbetween[ event in Orlando. This is a FREE event and well worth the time.
Wednesday, June 18th I'll be presenting "Silverlight 2 for Data Applications" at the Western New York .Net Users Group in Buffalo, NY
|
 |
|
Comments (1)
|
|
|
|
DeepZoom for eCommerce |
|
Andy's Blog
|
By Andy Beaulieu on
5/20/2008 8:33 PM
|
|
|
|
It just so happens my father-in-law is a woodworker who creates some really fantastic pieces and has contemplated selling them online for some time. But limiting the shopper to a few small thumbnail images wouldn't do his work justice.
Enter Silverlight's MutliScaleImage class (aka "DeepZoom"). Chances are you've seen DeepZoom in action on sites like the Hardrock Memorabilia site. DeepZoom provides progressive image downloads with an intuitive navigation system that looks like something out of Minority Report.
So here is the site we pulled together using DeepZoom, Silverlight, and some really impressive wood turnings:
One of the irritations with buying stuff on the web is that you can't hold the item in your hand and really check it out before forking over your credit card info. This can be especially irritating if the item you're looking at is hand-made, such as a painting, piece of pottery, or... a bowl turning! I think technologies like DeepZoom can greatly improve this experience over traditional thumbnail images.
Notice how the site also uses a picture-in-picture type view for some of the pieces, to show different views - such as the item with the top removed:

... the neat thing here is that the smaller picture-in-picture image has all of the detail of the main image.
Shameless Plug: If you are looking for a one of a kind, hand-made gift please browse the site!
Lessons Learned: It turns out there is a surprising amount of code you need to write yourself to get a DeepZoom implementation such as the one at wssmithers.com. You might expect most functionality would be built into the MultiScaleImage class, but it isn't!
One of the key requirements of the site was to be able to tie the product information (item #, price, etc) from a SQL Server db to the Images in the DeepZoom Composer project. In order to create this relationship, you can use the index # of the subimage as a unique key in the composition.
So first, we handle the ImageOpenSucceeded event of the MultiScaleImage Control:
deepZoomObject.ImageOpenSucceeded += new RoutedEventHandler(deepZoomObject_ImageOpenSucceeded);
... and in that handler we can store the image index along with relevant data (perhaps a ProductId) to tie the image to its data:
Dictionary<string, string> _imageData = new Dictionary<string, string>();
private void deepZoomObject_ImageOpenSucceeded(object sender, RoutedEventArgs e)
{
_imageData.Clear();
for (int i = 0; i < deepZoomObject.SubImages.Count; i++)
{
MultiScaleSubImage subImage = deepZoomObject.SubImages[i];
_imageData.Add(i.ToString(), "You can tie data here");
subImage.SetValue(FrameworkElement.NameProperty, i.ToString());
}
}
There are many other aspects to creating a DeepZoom site such as this which I hope to explain in a future blog post and maybe prepare a talk on the subject!
|
 |
|
Comments (5)
|
|
|
|
Where is my Astoria Client for Silverlight 2? |
|
Andy's Blog
|
By Andy Beaulieu on
4/25/2008 9:04 AM
|
|
|
|
According to this post from the Astoria Team Blog, it looks like we won't have a new Astoria (ADO.NET Data Services) client for Silverlight 2 until SL2 Beta 2 is released (perhaps May 2008?)
Many of the data demos for Silverlight 2 have so far used LINQ to SQL for the data access layer. These demos involve creating a LINQ to SQL data model (using a nice drag/drop editor), and then exposing that model through a web service by manually coding a WCF Web Service or .asmx Service.
Don't get me wrong, this is a pretty rapid development method... but what if you didn't need to code the web service for basic CRUD operations and queries on your data? What if it were all exposed for you and you could use LINQ to access the data from the Silverlight client?
This automatic service layer is just one of the advantages that ADO.NET Data Services (Astoria) provides, and since Silverlight 2 has much better support for Data Entry controls, the combination of SL and Astoria should provide a powerful rapid development environment!
|
 |
|
Comments (2)
|
|
|
|
Silverlight 2 for Data Apps |
|
Andy's Blog
|
By Andy Beaulieu on
4/6/2008 5:59 PM
|
|
|
|
Thanks to everyone who attended my "Silverlight 2 for Data Applications" talk at Code Camp 9 in Waltham, MA on 4/5/2008! And a big thanks to Chris Bowen and Chris Pels for their hard work organizing this great event time after time. I had a great crowd for my talk, standing room only, and as promised I have some goodies for all:
First, even if you couldn't make it to Code Camp for my talk, I have created a screen cast that walks through the demos. Just click the image below to launch the video:
I also have the Beers Demo Application and Slide Deck available:
DOWNLOAD THE DEMO CODE
DOWNLOAD THE SLIDE DECK (PPT)
Summary of the Presentation
In this talk, I walked through a mult-tier Silverlight Application with the following architecture:
1. A Silverlight 2 Client containing a Master/Detail scenario
2. A WCF Web Service providing communication to the Silverlight Client
3. A Data Accesss Layer using LINQ to SQL
4. A Simple SQL Server Database with (Mmmmm) Beer Data.
We explored how to use LINQ to SQL to expose our database entities through a WCF Web Service, and how Silverlight 2 can communicate with the web service. We also explored formatting a DataGrid and creating User Controls with DataBound UI Elements, and how to do basic CRUD operations from the Silverlight client back to the Web Service.
Here is a shot of the completed demo (download the source code above):

|
 |
|
Comments (3)
|
|
|
|
LINQ to SQL CRUD |
|
Andy's Blog
|
By Andy Beaulieu on
3/28/2008 12:42 PM
|
|
|
|
I'm seeing a lot of buzz around LINQ to SQL lately and how it can help to quickly create a Silverlight 2 data app.
I'll be giving a talk around this at the upcoming Code Camp 9 in Waltham, MA, and I wanted to share how I am doing basic CRUD operations in LINQ to SQL, as I've seen this question come up a few times.
You may remember my Silverlight 1.1 Alpha demo app, "Andy's Fridge." I'll be using a similar Beer Database which has a very simple schema containing Beers and Brewers like so:

It's important to note that the RowVersionId columns in the diagram are Timestamp columns. This will allow LINQ to SQL to generate more efficient Update statements, based on the unique Row Id (timestamp) instead of Where clauses with lots of logical "AND's" for each original value.
So, given that schema is like that above, our CRUD operations for the Beer entity would exist in our web service like so:
public class BeerService : IBeerService
{
public List<Beer> GetAllBeers()
{
DataClassesDataContext db = new DataClassesDataContext();
var beers = from b in db.Beers
orderby b.BeerName
select b;
return beers.ToList<Beer>();
}
public void SaveBeer(Beer beer)
{
DataClassesDataContext db = new DataClassesDataContext();
if (beer.BeerId > 0)
{
// this is an update
db.Beers.Attach(beer, true);
}
else
{
// this is an insert
db.Beers.InsertOnSubmit(beer);
}
db.SubmitChanges();
}
public void DeleteBeer(Beer beer)
{
DataClassesDataContext db = new DataClassesDataContext();
db.Beers.Attach(beer, false);
db.Beers.DeleteOnSubmit(beer);
db.SubmitChanges();
}
}
Note that I piggybacked the SaveBeer method to do either an Insert operation or Update operation, based on whether or not a primary key is available in the passed entity.
I guess until ADO.NET Data Services (Astoria) and the Entity Framework are officially available, we will have to settle with LINQ to SQL for Data Access! But I don't think we will be waiting long :)
What can we look forward to with Astoria and the EF?
- no need to write tedious web service methods for CRUD operations like shown above
- serialization of Parent and Child records (LINQ to SQL cannot pass related child records across the wire with parent rows)
- Access to other Database Providers other than SQL Server.
- The ability to flexibly map Conceptual model elements such as class properties to Physical columns in the database (LINQ to SQL provides only a 1-to-1 mapping)
|
 |
|
Comments (2)
|
|
|
|
When in Beta, Not all Locales are Created Equal? |
|
Andy's Blog
|
By Andy Beaulieu on
3/18/2008 4:11 PM
|
|
|
|
I ran into an odd Silverlight Beta 1 problem after releasing the latest version of "Sort the Foobars" - the game worked fine for me in testing, but shortly after putting it up on this site I received several comments about it crashing in different locales, like Russian and French (you can see those comments here)
The exception looked something like this:
Silverlight error message ErrorCode: 4002 ErrorType: ManagedRuntimeError Message: System.Exception: Défaillance irrémédiable (Error 0x1709. Debugging resource strings are unavailable. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=mscorrc.dll&Key=0x1709 0x8000FFFF (E_UNEXPECTED)) at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(IntPtr oPtr, UInt32 iPropertyId, String s) at MS.Internal.XcpImports.SetValue(IntPtr oPtr, UInt32 iPropertyId, Object obj) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean isSetByStyle, Boolean isSetByBuiltInStyle) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
So the first question is, how do you set up your development machine to test the other locales? It turns out this part is easy - go to Control Panel/Regional Settings and set the language to, say Russian.
After doing that, I found that this was the line of code that was dying:
this.SetValue(Canvas.LeftProperty, X)
Not much to that… “this” is a UserControl and (here is the key part!) “X” is a float. So apparently, setting the left property to a float is bad outside of en-us J
I added a Convert.ToDouble(X) in there and it seems happy now:
this.SetValue(Canvas.LeftProperty, Convert.ToDouble(X))
So the moral of the story? I think that the different behavior is hopefully because this is still a Beta release of Silverlight... Because we would really hope for consistent behavior between Locales! But on the other hand, you still need to be careful with setting Dependency properties to types that they aren't suited for!
|
 |
|
Comments (3)
|
|
|
|
Calling an .asmx Web Service in Silverlight 2 |
|
Andy's Blog
|
By Andy Beaulieu on
3/17/2008 6:14 PM
|
|
|
|
I wanted to share a couple of tips for calling web services from a Silverlight client.
If you are just beginning to useWeb Services from a Silverlight 2 Client, Tim Heuer has a good introductory post here.
Getting the Binding Url A lot of the web service samples will show the binding created with a hardcoded Uri such as this:
WebServiceSoapClient webSvc = new WebServiceSoapClient(binding, new System.ServiceModel.EndpointAddress("http://localhost/MyWebService.asmx"));
The problem being of course that the EndpointAddress is hardcoded to localhost, and you may not know what server you will ultimately deploy to. You could add the Uri as a configuration setting, but there is a more flexible way.
Chances are, your web service is hosted on the same web server that your Silverlight application downloads from. So when you create your Web Service binding, you can determine the Url for you service to bind to based on the current browser Uri:
public static string GetUrlForResource(string resourcePage) { string webUrl = System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString();
string containerPage = webUrl.Substring(webUrl.LastIndexOf("/") + 1);
webUrl = webUrl.Replace(containerPage, resourcePage);
return webUrl;
}
... So the method above, when passed a resource string such as "MyWebService.asmx" will return a full Url for a page that is in the same virtual directory as the silverlight app.
When binding, you can then use this utility method like so:
// get the full url of the Web Service string webServiceUrl = GetUrlForResource("WebService.asmx");
System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
WebServiceSoapClient webSvc = new WebServiceSoapClient(binding, new System.ServiceModel.EndpointAddress(webServiceUrl));
webSvc.HelloWorldCompleted += new EventHandler<HelloWorldCompletedEventArgs>(webSvc_HelloWorldCompleted); webSvc.HelloWorldAsync();
Keep an Eye on MaxReceivedMessageSize If your web service is returning a lot of data, you may blow out the default max message size for a return. If this happens you will get an exception like so:
An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: [MaxReceivedMessageSizeExceeded]
To remedy this, you can up the MaxReceivedMessageSize attribute of the binding like so:
System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
// if you are getting a LOT of data back, you will need to up Message Size binding.MaxReceivedMessageSize = int.MaxValue;
|
 |
|
Comments (8)
|
|
|
|
|
|
|
|
 |
|
 |
|
|