11 Jul 2010 @ 1:35 PM 

In my solution, I have a Silverlight application using WCF services and a single DataModels.cs file with contents similar to the following. The only thing to remember is to add the WindowsBase reference to your WCF service project in order to use the same ObservableCollection<> template object.
(in my case, I put DataModels.cs in the WCF project, and created a virtual file link to it from the Silverlight project)

This is a sample of the code I use:
____________________________________________________ ____________________________________________

// <...other using statements...>
using System.Collections.ObjectModel; // ObservableCollection<> is added via WindowsBase (WindowsBase.dll).

#if !SILVERLIGHT
[DataContract]
public partial class CPPLoginState
{
    [DataMember]
    public bool Ok { get; set; }
    [DataMember]
    public string UserName { get; set; }
    [DataMember]
    public Int32 UserID { get; set; }
    [DataMember]
    public ObservableCollection Roles { get; set; }
}
#endif
public partial class CPPLoginState
{
    public CPPLoginState()
    {
        Ok = false;
        UserName = "";
        UserID = 0;
        Roles = new ObservableCollection();
    }
}

________________________________________________________________________________________________

The trick here is in the Silverlight proxy’s use of the “partial” modifier for it’s class definitions. This allows “adding” code to them. :)

I must say, it only took one week working with Silverlight (from knowing nothing, not even WPF) and I’m almost done with a fairly complicated control library and host application. Silverlight + WCF really does == RAD development. :D

Share
Posted By: James
Last Edit: 13 Jul 2010 @ 01:35 AM

EmailPermalinkComments (0)
Tags
Tags: , ,
Categories: Silverlight
 11 Jul 2010 @ 3:36 AM 

So, you have two projects: WCF & Silverlight, and put a break point on code in a shared class between the two projects. Visual Studio breaks on the line, but as soon as you hit F10 or F11, the code simply “continues” as if to ignore your step request.

This very scenario really messed with me for a few months, and the reason I didn’t investigate much at the time was because I could simply create many breakpoints and run between them. Recently, however, I had code too complex to keep doing this without pulling my hair out, so I investigated again and suddenly got an idea regarding meta data. Perhaps there’s an option preventing this from working on the “root” class. You see, Silverlight-side service references create classes from server side data types (where specified), and my shared code was using partial classes to add methods to both sides (server and client). The problem is that the shared code file isn’t decorated with meta data tags, but the auto-generated client-side code IS, and in fact, this was the line:

[System.Diagnostics.DebuggerStepThroughAttribute()]

So, I did a “replace all” to clear all occurrences and presto! My life just got a little better. ;)

Share
Posted By: James
Last Edit: 13 Jul 2010 @ 01:36 AM

EmailPermalinkComments (0)
Tags

 Last 50 Posts
 Back
Change Theme...
  • Users » 17
  • Posts/Pages » 65
  • Comments » 3
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Games



    No Child Pages.

About/Help



    No Child Pages.

Contact



    No Child Pages.