<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silverlight Hosting News (SuperBlogAds Network)</title>
	<atom:link href="http://www.silverlighthostingnews.com/index.php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.silverlighthostingnews.com</link>
	<description>News about Silverlight Hosting, Silverlight 4 Hosting and WCF RIA Service Hosting</description>
	<lastBuildDate>Wed, 16 May 2012 04:00:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WCF RIA Hosting :: Using Attribute Validation in Silverlight with WCF RIA Services Example</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/758</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/758#comments</comments>
		<pubDate>Wed, 16 May 2012 04:00:36 +0000</pubDate>
		<dc:creator>Landon Ferguson</dc:creator>
				<category><![CDATA[WCF RIA Service Hosting]]></category>
		<category><![CDATA[cheap RIA services hosting]]></category>
		<category><![CDATA[cheap WCF hosting]]></category>
		<category><![CDATA[cheap WCF RIA hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[wcf hosting]]></category>
		<category><![CDATA[wcf ria hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=758</guid>
		<description><![CDATA[<p>In this example I&#8217;ll use WCF RIA services because it can wire the example up quickly, it automatically projects the data annotations, and because I get a lot of people who ask me for examples using WCF RIA. The example here will work just as well if you use your own POCO classes with annotations in <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/758">WCF RIA Hosting :: Using Attribute Validation in Silverlight with WCF RIA Services Example</a></span>]]></description>
			<content:encoded><![CDATA[<p>In this example I&#8217;ll use WCF RIA services because it can wire the example up quickly, it automatically projects the data annotations, and because I get a lot of people who ask me for examples using WCF RIA. The example here will work just as well if you use your own POCO classes with annotations in a shared library and send them across the wire with a REST service using JSON.</p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>First, a simple class to encapsulate some data that is decorated with the annotations:</p>
<pre>public class Contact
{
    [Key]
    public int Id { get; set; }

    [Required]
    public string FirstName { get; set; }

    public string LastName { get; set; }

    [Required]
    [RegularExpression(@"^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$",
        ErrorMessage = "Email is invalid.")]
    public string Email { get; set; }
}</pre>
<p>Next, a simple domain service that exposes what WCF RIA wants to think it is talking to a database layer. Note I am stubbing the CRUD to allow for edits on the client but don&#8217;t really care about processing them for this example. The one query always returns an example with my information in it.</p>
<pre>[EnableClientAccess()]
public class ContactDomainService : DomainService
{
    public Contact GetContact(int contactId)
    {
        return new Contact
                    {
                        Id = contactId,
                        FirstName = "Jeremy",
                        LastName = "Likness",
                        Email = "jeremy@jeremylikness.com"
                    };
    }

    [Insert]
    public void InsertContact(Contact contact)
    {

    }

    [Delete]
    public void DeleteContact(Contact contact)
    {

    }

    [Update]
    public void UpdateContact(Contact contact)
    {

    }
}</pre>
<p>This is where the beauty of WCF RIA services comes into play, and I won&#8217;t deny it: build the application, and you&#8217;re ready to go with grabbing and manipulating the data on the client. Before you build the view model you can create a helper class that uses the data annotations validation to process the attributes on the entity. While I wouldn&#8217;t normally overload the same class to also take on the work of a command, the helper will also implement ICommand to demonstrate how it can be used to also control whether or not the user is able to save the form based on validations (this keeps the example simple &#8211; normally I would have a second command class that interacts with the validation helper).</p>
<p>The bulk of the class is straightforward. It is typed to a class that implements property change notification, and registers for this (it also exposes a method to release the registration to avoid issues with memory leaks). Whenever a property changes, it uses reflection to grab the value and then passes all of the information over to the data annotations validation class. That class will throw an exception if the validation fails, and the helper traps this and uses it to keep track of properties that have validation errors before re-throwing it for the Silverlight validation system to use. I&#8217;m keeping it simple here and using strings but you can tweak it based on this post.</p>
<pre>public class ValidationHelper&lt;T&gt; : ICommand where T : class, INotifyPropertyChanged
{
    private readonly T _instance;

    private readonly Dictionary&lt;string,bool&gt;  _hasErrors
        = new Dictionary&lt;string, bool&gt;();

    public ValidationHelper(T instance)
    {
        _instance = instance;
        _instance.PropertyChanged += _InstancePropertyChanged;
    }

    public void Release()
    {
        if (_instance != null)
        {
            _instance.PropertyChanged -= _InstancePropertyChanged;
        }
    }

    private void _InstancePropertyChanged(object sender, PropertyChangedEventArgs e)
    {

        _hasErrors[e.PropertyName] = false;            

        var value =
            typeof (T)
                .GetProperty(e.PropertyName)
                .GetGetMethod()
                .Invoke(_instance, null);

        try
        {
            Validator.ValidateProperty(
                value,
                new ValidationContext(_instance, null, null)
                    {
                        MemberName = e.PropertyName
                    });
        }
        catch
        {
            _hasErrors[e.PropertyName] = true;
            throw;
        }
        finally
        {
            RaiseCanExecuteChange();
        }
    }
}</pre>
<p>The implementation of the command interface takes one more step. Because a user might change some text and then click submit before validation fires, the command implementation will validate the entire object before determining whether or not it is safe to submit. The command is conditioned by the existence of any errors in the error dictionary. Note that the execute methods uses a different approach that doesn&#8217;t throw exceptions and simply flags the individual errors generated by the call.</p>
<pre>public bool CanExecute(object parameter)
{
    return _hasErrors.Keys.All(key =&gt; !_hasErrors[key]);
}

public void Execute(object parameter)
{
    var errors = new List&lt;ValidationResult&gt;();

    if (Validator.TryValidateObject(
        _instance,
        new ValidationContext(_instance, null, null),
        errors))
    {
        MessageBox.Show("Success!");
    }
    else
    {
        foreach (var member in errors.SelectMany(error =&gt; error.MemberNames))
        {
            _hasErrors[member] = true;
        }
        RaiseCanExecuteChange();
    }
}</pre>
<p>The view model keeps an instance of the validation helper and tracks changes to the current contact, spinning up a new helper as needed. It also exposes an edit flag to disable editing while it is loading the data.</p>
<pre>public class MainViewModel : INotifyPropertyChanged
{
    private ValidationHelper&lt;Contact&gt; _helper;
    private Contact _contact;

    private readonly string[] _properties =
        new[] {"FirstName", "LastName", "Email"};

    protected Contact CurrentContact
    {
        get { return _contact; }
        set
        {
            if (_helper != null)
            {
                _helper.Release();
                _helper = null;
            }

            _contact = value;

            if (_contact != null)
            {
                CanEdit = true;
                _helper = new ValidationHelper&lt;Contact&gt;(value);
                RaisePropertyChange("SaveCommand");
            }

            RaisePropertyChange("Contact");
            foreach(var property in _properties)
            {
                RaisePropertyChange(property);
            }
        }
    }

    private bool _canEdit;
    public bool CanEdit
    {
        get { return _canEdit; }
        set
        {
            _canEdit = value;
            RaisePropertyChange("CanEdit");
        }
    }
}</pre>
<p>It exposes the validation helper as a command and also projects all of the properties on the underlying contact object:</p>
<pre>public ICommand SaveCommand
{
    get { return _helper; }
}        

public string FirstName
{
    get { return CurrentContact == null ? string.Empty : CurrentContact.FirstName; }
    set { CurrentContact.FirstName = value; }
}

public string LastName
{
    get { return CurrentContact == null ? string.Empty : CurrentContact.LastName; }
    set { CurrentContact.LastName = value; }
}

public string Email
{
    get { return CurrentContact == null ? string.Empty : CurrentContact.Email; }
    set { CurrentContact.Email = value; }
}</pre>
<p>In the constructor, it either creates a design-time instance or uses WCF RIA services to load an instance of the contact record:</p>
<pre>public MainViewModel()
{
    if (DesignerProperties.IsInDesignTool)
    {
        CurrentContact = new Contact
                        {
                            Id = 1,
                            Email = "jeremy@jeremylikness.com",
                            FirstName = "Jeremy",
                            LastName = "Likness"
                        };
        return;
    }

    var ctx = new ContactDomainContext();

    var query = ctx.GetContactQuery(1);
    ctx.Load(
        query,
        contact =&gt;
            {
                CurrentContact = contact.Entities.Single();
            },
        null);
}</pre>
<p>The Xaml to wire this up is straightforward &#8211; here is an example combination of a label and a text box:</p>
<pre>&lt;TextBlock Text="Last Name:" Grid.Row="1"/&gt;
&lt;TextBox Text="{Binding Path=LastName, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
            IsEnabled="{Binding Path=CanEdit}"
            Grid.Row="1"
            Grid.Column="1"/&gt;</pre>
<p>That&#8217;s it &#8211; run the application and edit the fields. You&#8217;ll see all of the attribute validations come across nicely. If you delete the first name, then click the submit button without tabbing out of the field, the validations will still fire and the submit button will disable itself until you fix the error. As you can see, it&#8217;s very straightforward to tap into existing attribute-based validations. If you are implementing one of the newer interfaces like <code>INotifyDataErrorInfo</code>, you can use the &#8220;try&#8221; methods on the validator to avoid throwing exceptions, and parse the results to set errros on the underlying interface instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/758/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 5 Hosting :: Using Custom Markup Extensions in Silverlight 5</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/706</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/706#comments</comments>
		<pubDate>Mon, 16 Apr 2012 04:27:55 +0000</pubDate>
		<dc:creator>Mark Latchey</dc:creator>
				<category><![CDATA[Silverlight 5 Hosting]]></category>
		<category><![CDATA[cheap silverlight 5 hosting]]></category>
		<category><![CDATA[cheap wcf 4.5 hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[silverlight hosting]]></category>
		<category><![CDATA[wcf 4.5 ria hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=706</guid>
		<description><![CDATA[<p>In this post, Iâ€™d like to present a custom markup extension of my own â€“ one that retrieves RESX localization resources and simplifies the task of adding localization support to Silverlight applications.</p>

<p>In the past, RESX-based localization was usually performed in Silverlight XAML with the help of the built-in {Binding} markup extension. To demonstrate, the following example <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/706">Silverlight 5 Hosting :: Using Custom Markup Extensions in Silverlight 5</a></span>]]></description>
			<content:encoded><![CDATA[<p>In this post, Iâ€™d like to present a custom markup extension of my own â€“ one that retrieves RESX localization resources and simplifies the task of adding localization support to Silverlight applications.</p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>In the past, RESX-based localization was usually performed in Silverlight XAML with the help of the built-in {Binding} markup extension. To demonstrate, the following example declares an instance of the ResourceManager wrapper class named Resources (which is generated by Visual Studio from Resources.resx), assigns the Resources instance to the DataContext property of a TextBlock, and uses a data-binding expression to set the TextBlockâ€™s Text property equal to the Greeting property of the Resources instance:</p>
<p><code>&lt;Grid&gt;<br />
&lt;Grid.Resources&gt;<br />
&lt;local:Resources x:Key="Localize" /&gt;<br />
&lt;/Grid.Resources&gt;<br />
&lt;TextBlock Text="{Binding Greeting}" DataContext="{StaticResource Localize}" /&gt;<br />
&lt;/Grid&gt;</code></p>
<p>It works, but it makes you wonder why you have to resort to data binding to make localization work when localization is such a common task in Silverlight applications.</p>
<p>You can make this work a little more cleanly by writing a custom markup extension. Such an extension might be applied this way:</p>
<p><code>&lt;Grid&gt;<br />
&lt;TextBlock<br />
Text="{local:Resx ResxKey=Greeting, ResxType=Resources, Default=Welcome}" /&gt;<br />
&lt;/Grid&gt;</code></p>
<p>In this example, Resx is the custom markup extension, ResxKey identifies the localization resource to be loaded, ResxType identifies the ResourceManager wrapper class that provides access to that resource, and Default is an optional default value thatâ€™s used if the specified localization resource doesnâ€™t exist or canâ€™t be retrieved. Better, is it not? And itâ€™s just one of a million different applications for custom markup extensions.</p>
<p>Implementing a custom markup extension is, in most cases, relatively straightforward. You begin by deriving from Silverlight 5â€™s new System.Windows.Markup.MarkupExtension class. Then you override ProvideValue in the derived class and return the value generated by the markup extension. My ResxExtension class is implemented this way:</p>
<p><code>public class ResxExtension : MarkupExtension<br />
{<br />
public string ResxType { get; set; }<br />
public string ResxKey { get; set; }<br />
public object Default { get; set; }</p>
<p>public override object ProvideValue(IServiceProvider serviceProvider)<br />
{<br />
if (!String.IsNullOrEmpty(ResxType) &amp;&amp; !String.IsNullOrEmpty(ResxKey))<br />
{<br />
try<br />
{<br />
// Create a strongly typed resource manager instance<br />
object resman = Activator.CreateInstance(Type.GetType(ResxType));</p>
<p>// Get the value of the specified property<br />
PropertyInfo pi = resman.GetType().GetProperty(ResxKey);<br />
return pi.GetValue(resman, null);<br />
}<br />
catch (Exception)<br />
{<br />
// Purposely do nothing here to allow the call to fall through<br />
}<br />
}</p>
<p>// If we make it to here, return the default value (if specified) or,<br />
// as a last resort, the key name<br />
if (Default != null)<br />
return Default;<br />
else<br />
return ResxKey;<br />
}<br />
}</code></p>
<p>The three public properties â€“ ResxType, ResxKey, and Default â€“ define the named parameters that the markup extension accepts. The XAML parser automatically initializes these properties with the values provided in the markup. My ProvideValue override uses reflection to create an instance of the ResourceManager wrapper class identified by ResxType, and then uses reflection again to retrieve the value of the property whose name is stored in the markup extensionâ€™s ResxKey property. If anything goes wrong, ProvideValue returns the default value specified with the Default parameter, or the value of ResxKey if there is no Default parameter.</p>
<p>When you run the app for the first time, youâ€™ll see this:</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/04/image_1d.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/04/image_1d.png" alt="" title="image_1" width="387" height="301" class="aligncenter size-full wp-image-707" /></a></p>
<p>But if you open App.xaml.cs and uncomment line of code that sets the culture to French, youâ€™ll see this instead:</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/04/image_2.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/04/image_2.png" alt="" title="image_2" width="388" height="302" class="aligncenter size-full wp-image-708" /></a></p>
<p>The welcome text, the URI of the flag image, and the width of the flag image come from RESX files named Resources.resx, Resources.fr.resx, Resources.es.resx, and Resources.de.resx. Open these RESX files in Visual Studio and youâ€™ll see exactly how the individual resources are defined. As for applying the localization resources, that happens in MainPage.xaml:</p>
<p><code>&lt;TextBlock Text="{local:Resx ResxKey=Greeting,<br />
ResxType=CustomMarkupExtensionDemo.Localization.Resources, Default='Nice Try!'}"<br />
Foreground="LightYellow" FontSize="72" FontWeight="Bold"<br />
HorizontalAlignment="Center" VerticalAlignment="Center"&gt;<br />
&lt;TextBlock.Effect&gt;<br />
&lt;DropShadowEffect BlurRadius="12" ShadowDepth="12" Opacity="0.5" /&gt;<br />
&lt;/TextBlock.Effect&gt;<br />
&lt;/TextBlock&gt;<br />
&lt;Image Source="{local:Resx ResxKey=FlagUri,<br />
ResxType=CustomMarkupExtensionDemo.Localization.Resources}"<br />
Width="{local:Resx ResxKey=FlagWidth,<br />
ResxType=CustomMarkupExtensionDemo.Localization.Resources}" /&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/706/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 5 Hosting :: DoubleClickInvokeCommandBehavior in Silverlight 5</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/703</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/703#comments</comments>
		<pubDate>Wed, 04 Apr 2012 03:44:44 +0000</pubDate>
		<dc:creator>Landon Ferguson</dc:creator>
				<category><![CDATA[Silverlight 5 Hosting]]></category>
		<category><![CDATA[cheap silverlight 5 hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[silverlight hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=703</guid>
		<description><![CDATA[<p>Today, I was working on PodTower a bit more, and needed a way to add items to the new playlist coming in PodTower 2. While I plan on adding drag and drop at a later date, for now I decided that double-clicking on an item in the podcast list will add it to the current playlist.</p>

<p>So, <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/703">Silverlight 5 Hosting :: DoubleClickInvokeCommandBehavior in Silverlight 5</a></span>]]></description>
			<content:encoded><![CDATA[<p>Today, I was working on PodTower a bit more, and needed a way to add items to the new playlist coming in PodTower 2. While I plan on adding drag and drop at a later date, for now I decided that double-clicking on an item in the podcast list will add it to the current playlist.</p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>So, I decided to break out a behavior for this task. Using the new ClickCount property provided by the MouseButtonEventArgs class (<a href="http://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs%28v=vs.96%29.aspx">MSDN Documentation here</a>), I was able to count the number of clicks, and if it was equal to 2, invoke a Command. Since Behaviors inherit from DependencyObject, they can participate in the binding system as well. Combine this with the new RelativeSource binding support in Silverlight 5, this opens up a whole new realm of binding possibilities! For PodTower, I have the behavior bound to a property of the DataContext on the main UserControl of the application. This allows me to bind up to the Commands on the viewmodel without having to do horrible back-end hack code.</p>
<p>Without further ado, hereâ€™s the code for the behavior. Note that Iâ€™ve included a conditional symbol called SILVERLIGHT5, so that if you want to use this behavior in Silverlight 4, you can.</p>
<pre>using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity; Â Â 

namespace PodTower
{
Â Â Â  public class DoubleClickInvokeCommandBehavior : Behavior&lt;UIELEMENT&gt;
Â Â Â  {
Â Â Â Â Â Â Â  public ICommand Command
Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â  get { return (ICommand)GetValue(CommandProperty); }
Â Â Â Â Â Â Â Â Â Â Â  set { SetValue(CommandProperty, value); }
Â Â Â Â Â Â Â  } Â Â 

Â Â Â Â Â Â Â  public static readonly DependencyProperty CommandProperty =
Â Â Â Â Â Â Â Â Â Â Â  DependencyProperty.Register("Command", typeof(ICommand), typeof(DoubleClickInvokeCommandBehavior), new PropertyMetadata(null)); Â Â 

Â  Â Â Â Â Â Â public Object CommandParameter
Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â  get { return (Object)GetValue(CommandParameterProperty); }
Â Â Â Â Â Â Â Â Â Â Â  set { SetValue(CommandParameterProperty, value); }
Â Â Â Â Â Â Â  } Â Â 

Â Â Â Â Â Â Â  public static readonly DependencyProperty CommandParameterProperty
=
Â Â Â Â Â Â Â Â Â Â Â  DependencyProperty.Register("CommandParameter", typeof(Object), typeof(DoubleClickInvokeCommandBehavior), new PropertyMetadata(null)); Â Â 

Â Â Â Â Â Â Â  protected override void OnAttached()
Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â  base.OnAttached(); Â Â 

Â Â Â Â Â Â Â Â Â Â Â  this.AssociatedObject.MouseLeftButtonDown += OnClick;
Â Â Â Â Â Â Â  } Â Â 

Â Â Â Â Â Â Â  protected override void OnDetaching()
Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â  base.OnDetaching();
Â Â Â Â Â Â Â Â Â Â Â  this.AssociatedObject.MouseLeftButtonDown -= OnClick;
Â Â Â Â Â Â Â  } Â Â 

#if !SILVERLIGHT5
Â Â Â Â Â Â Â  DateTime? _lastClick;
#endif Â Â 

Â Â Â Â Â Â Â  void OnClick(object sender, MouseButtonEventArgs e)
Â Â Â Â Â Â Â  {
#if SILVERLIGHT5
Â Â Â Â Â Â Â Â Â Â Â  if (e.ClickCount != 2)
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  return;
#else
Â Â Â Â  Â Â Â Â Â Â Â if (_lastClick == null)
Â Â Â Â Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  _lastClick = DateTime.Now;
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  return;
Â Â Â Â Â Â Â Â Â Â Â  }
Â Â Â Â Â Â Â Â Â Â Â  else
Â Â Â Â Â Â Â Â Â Â Â  {
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  var now = DateTime.Now;
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  var last = _lastClick.Value;
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  _lastClick = now; Â Â 

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  if (now.Subtract(last).TotalMilliseconds &gt; 250)
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  return;
Â Â Â Â Â Â Â Â Â Â Â  }
#endif
Â Â Â Â Â Â Â Â Â Â Â  if (this.Command == null || !this.Command.CanExecute(this.CommandParameter))
Â Â Â Â Â Â Â Â Â Â  Â Â Â Â Â return; Â Â
Â Â Â Â Â Â Â Â Â Â Â  this.Command.Execute(this.CommandParameter);
Â Â Â Â Â Â Â  }
Â Â Â  }
}</pre>
<p>â€¦and hereâ€™s an example of it used in the PodTower main UI.</p>
<pre>&lt;DATATEMPLATE x:Key="PodcastItemTemplate"&gt;
Â Â Â Â Â Â Â Â Â Â  Â &lt;GRID Background="#00000000"&gt;
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  &lt;I:INTERACTION.BEHAVIORS&gt; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &lt;CONVERT:DOUBLECLICKINVOKECOMMANDBEHAVIOR CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Command="{Binding DataContext.MediaPlayer.AddToPlaylistCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" /&gt;
Â Â Â Â Â Â Â Â Â Â Â  Â Â Â Â &lt;/I:INTERACTION.BEHAVIORS&gt;
Â Â Â Â Â Â Â Â Â Â Â  &lt;/GRID&gt;
Â Â Â Â Â Â Â  &lt;/DATATEMPLATE&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/703/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF Hosting :: How to Fix Error -The underlying connection was closed: An unexpected error occurred on a receive.</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/701</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/701#comments</comments>
		<pubDate>Thu, 22 Mar 2012 05:14:08 +0000</pubDate>
		<dc:creator>Landon Ferguson</dc:creator>
				<category><![CDATA[WCF RIA Service Hosting]]></category>
		<category><![CDATA[cheap hosted RIA services]]></category>
		<category><![CDATA[cheap WCF hosting]]></category>
		<category><![CDATA[cheap WCF RIA hosting]]></category>
		<category><![CDATA[cheap wcf service hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[wcf ria hosting]]></category>
		<category><![CDATA[wcf service hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=701</guid>
		<description><![CDATA[<p>This is another installment in the WCF vs. WTF article series. I mentioned before that I am quite a fan of WCF but having said that, feel that there are a few areas for improvement like sending method comments with the service contract discovery and more streamlined debugging, to name a couple.</p>
<p>The truth is that WCF <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/701">WCF Hosting :: How to Fix Error -The underlying connection was closed: An unexpected error occurred on a receive.</a></span>]]></description>
			<content:encoded><![CDATA[<p>This is another installment in the WCF vs. WTF article series. I mentioned before that I am quite a fan of WCF but having said that, feel that there are a few areas for improvement like sending method comments with the service contract discovery and more streamlined debugging, to name a couple.</p>
<p>The truth is that WCF actually provides some decent tools to debug service issues. However, I feel that the tools are a bit cumbersome to use and the bigger issue that the exception that bubbles up to the top is not necessarily informative of what actually caused the issue and requires digging deeper.</p>
<p>So.. Here is a pretty generic client error:</p>
<p>The underlying connection was closed: An unexpected error occurred on a receive. &#8211; at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(<br />
TimeSpan timeout)<br />
An error occurred while receiving the HTTP response to <a title="http://localhost:8731/Design_Time_Addresses/SomeService/" href="http://localhost:8731/Design_Time_Addresses/SomeService/">http://localhost:8731/Design_Time_Addresses/SomeService/</a>. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.</p>
<p>So this basically says that something went wrong on the server-side and the service closed the connection. I should also note, that it is certainly extremely useful to have the following option configured for the service behavior even though it promises a bit more than it delivers:</p>
<p><code>&lt;serviceBehaviors&gt;<br />
&lt;behavior name="SomeServiceBehavior"&gt;<br />
&lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;<br />
&lt;/behavior&gt;<br />
&lt;/serviceBehaviors&gt;</code></p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>I am generally pretty good at sticking an UnhandledException handler into my code but was surprised to find out that nothing was logged on the service to correspond to this client error. Hence, I took the next step and attached Visual Studio to the service and once again executed the client service call. Again, to my surprise, the breakpoint in the call got hit, I successfully stepped through the method right past the &#8216;return&#8217; statement and saw with my own eyes that a valid method response was being generated. Yet, the client crashed again&#8230;</p>
<p>When this happens (i.e. you *know* the service call got executed, but the client crashed), it typically means something went wrong in the WCF plumbing. In order to figure out what exactly went wrong, WCF provides us with the plumbing stethoscope that is service diagnostic listeners. As anything in WCF, it seems there are many ways to configure it, but essentially you need to tell the service which things to listen for and where to log them. So a couple of sections need to be added to the config file:</p>
<p><code>&lt;system.diagnostics&gt;<br />
&lt;sources&gt;<br />
&lt;source name="System.ServiceModel" switchValue="Warning, ActivityTracing"<br />
propagateActivity="true"&gt;<br />
&lt;listeners&gt;<br />
&lt;add type="System.Diagnostics.DefaultTraceListener" name="Default"&gt;<br />
&lt;filter type=""/&gt;<br />
&lt;/add&gt;<br />
&lt;add name="ServiceModelTraceListener"&gt;<br />
&lt;filter type=""/&gt;<br />
&lt;/add&gt;<br />
&lt;/listeners&gt;<br />
&lt;/source&gt;<br />
&lt;source name="System.ServiceModel.MessageLogging"<br />
switchValue="Warning, ActivityTracing"&gt;<br />
&lt;listeners&gt;<br />
&lt;add type="System.Diagnostics.DefaultTraceListener" name="Default"&gt;<br />
&lt;filter type=""/&gt;<br />
&lt;/add&gt;<br />
&lt;add name="ServiceModelMessageLoggingListener"&gt;<br />
&lt;filter type=""/&gt;<br />
&lt;/add&gt;<br />
&lt;/listeners&gt;<br />
&lt;/source&gt;<br />
&lt;/sources&gt;<br />
&lt;sharedListeners&gt;<br />
&lt;add initializeData="c:\wcfLogs\SomeService\app_tracelog.svclog"<br />
type="System.Diagnostics.XmlWriterTraceListener, System,<br />
Version=2.0.0.0,<br />
Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener"<br />
traceOutputOptions="Timestamp"&gt;<br />
&lt;filter type=""/&gt;<br />
&lt;/add&gt;<br />
&lt;add initializeData="c:\wcfLogs\SomeService\app_messages.svclog"<br />
type="System.Diagnostics.XmlWriterTraceListener, System,<br />
Version=2.0.0.0,<br />
Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener"<br />
traceOutputOptions="Timestamp"&gt;<br />
&lt;filter type=""/&gt;<br />
&lt;/add&gt;<br />
&lt;/sharedListeners&gt;<br />
&lt;/system.diagnostics&gt;</code></p>
<p>This snippet creates two listeners (message and service trace) and specified where they should be stored. Then, inside the serviceModel configuration we can also specify what types of messages to log. For example:</p>
<p><code>&lt;system.serviceModel&gt;<br />
&lt;diagnostics&gt;<br />
&lt;messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/&gt;<br />
&lt;/diagnostics&gt;</code></p>
<p>After adding the listeners, I ran the client again. Again it crashed, but now I had some logs created in &#8216;c:\wcfLogs\SomeService&#8221;.</p>
<p><strong>Note: </strong>The directory where the logs will go has to exist &#8211; it will not be automatically created!</p>
<p>Checking out the lgos, (in Microsoft Service Trace Viewer) more information came to light. The Trace Viewer breaks up different service activities (i.e. construction, service open call, service action request, etc) and nicely enough highlights in red where the errors occur.</p>
<p>In my case, in &#8216;Process action .. &#8216; activity I saw that the service was &#8216;Throwing and exception&#8221;, which presumably it was also catching, since my Unhandled Exception handler did not get hit. Click on the exception revealed these details:</p>
<p>Maximum number of items that can be serialized or deserialized in an object graph is &#8217;65536&#8242;. Change the object graph or increase the MaxItemsInObjectGraph quota.</p>
<p>Ok, now this seems more informative than &#8216;underlying connection was closed&#8217;.. Wonder why instead of closing the connection, the service could not communicate this exception to the client given the exceptionDetailsInFaults configuration&#8230; But anyway, at least now I had something to work with.</p>
<p>This error above just said that the number of objects in the data returned by the service call was too large to be serialized. Wonder why they had to limit it&#8230; But I changed the configuration in the service behavior to resemble this:</p>
<p><code>&lt;behaviors&gt;<br />
&lt;serviceBehaviors&gt;<br />
&lt;behavior name="SomeServiceServiceBehavior"&gt;<br />
&lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;<br />
&lt;dataContractSerializer maxItemsInObjectGraph="2147483647"/&gt;<br />
&lt;/behavior&gt;<br />
&lt;/serviceBehaviors&gt;<br />
&lt;/behaviors&gt;</code></p>
<p>No need to skimp on the maxItemsInObjectGraph, I say!</p>
<p>I restarted the service, ran the client&#8230; tun dun dun! and it crashed again. Well, this time, the exception on the client looked like this:</p>
<p>Maximum number of items that can be serialized or deserialized in an object graph is &#8217;65536&#8242;. Change the object graph or increase the MaxItemsInObjectGraph quota. &#8211; at System.Runtime.Serialization.XmlObjectSerializerContext.IncrementItemCount(Int32 count) at ReadSisyphusUriRecordFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )&#8230;..</p>
<p>What? It looks the same as the exception above!? Yep, except this time, it is on the client side and occurs around the same place where the &#8220;underlying connection was closed..&#8221; exception was happening before. So basically this says that the client <strong>de</strong>serializer also needs to be reconfigured. On the client side, this configuration needs to be specified for the behavior associated with the <strong><em>EndPoint.</em></strong> On the server side, it was a behavior associated with the service (i.e. within ServiceBehaviors). So a little tricky. The new client configuration change looked something like this:</p>
<p><code>&lt;behaviors&gt;<br />
&lt;endpointBehaviors&gt;<br />
&lt;behavior name="SomeServiceClientEndpointBehavior"&gt;<br />
&lt;dataContractSerializer maxItemsInObjectGraph="2147483647"/&gt;<br />
&lt;/behavior&gt;<br />
&lt;/endpointBehaviors&gt;<br />
&lt;/behaviors&gt;</code></p>
<p>This &#8216;Behaviors&#8217; defintion was added within the &lt;system.serviceModel&gt; tag, and then for the endpoint itself I added &#8216;behaviorConfiguration=&#8221;SomeServiceClientEndpointBehavior&#8221;&#8216; attribute.</p>
<p>That fixed the problem for me. Probably more than you wanted to know, but I hope this helps.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/701/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF RIA Hosting :: Use DomainServices as Service References</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/690</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/690#comments</comments>
		<pubDate>Mon, 19 Mar 2012 06:31:28 +0000</pubDate>
		<dc:creator>Mark Latchey</dc:creator>
				<category><![CDATA[WCF RIA Service Hosting]]></category>
		<category><![CDATA[cheap RIA services hosting]]></category>
		<category><![CDATA[cheap silverlight hosting]]></category>
		<category><![CDATA[cheap WCF RIA hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=690</guid>
		<description><![CDATA[
<p>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.</p>
<p>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 <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/690">WCF RIA Hosting :: Use DomainServices as Service References</a></span>]]></description>
			<content:encoded><![CDATA[<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>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.</p>
<p>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.</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_11.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_11.png" alt="" title="image_1" width="426" height="62" class="aligncenter size-full wp-image-691" /></a></p>
<p>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.</p>
<p>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 <strong>DomainServiceHttpModule</strong> http module is added to your web.config and <strong>ASP.NET compatibility</strong> is turned on.</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_21.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_21.png" alt="" title="image_2" width="470" height="213" class="aligncenter size-full wp-image-692" /></a></p>
<p>The DomainServiceHttpModule <strong>dynamically</strong> generates a WCF Service based on our DomainService. In this sample I have added a DomainService called <em>DomainService1</em> in the root of my ASP.NET web project called <em>WebApplication1</em>. The web project is using port 6479. Based on this information I can point to my dynamically generated WCF Service from my browser:</p>
<p><em>http://localhost:6479/Services/WebApplication1-DomainService1.svc</em></p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_3.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_3.png" alt="" title="image_3" width="771" height="196" class="aligncenter size-full wp-image-693" /></a></p>
<p>If I try to make a Service Reference to the WCF Service I will get an error:</p>
<p><em>There was no endpoint listening at http://localhost:6479/Services/WebApplication1-DomainService1.svc that could accept the message.</em></p>
<p>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.</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_41.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_41.png" alt="" title="image_4" width="628" height="104" class="aligncenter size-full wp-image-695" /></a></p>
<p>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).</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_5.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_5.png" alt="" title="image_5" width="632" height="152" class="aligncenter size-full wp-image-696" /></a></p>
<p>Finally I can add a Service Reference to the service and use it as if it was a regular WCF Service.</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_6.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_6.png" alt="" title="image_6" width="396" height="320" class="aligncenter size-full wp-image-697" /></a></p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_7.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_7.png" alt="" title="image_7" width="387" height="122" class="aligncenter size-full wp-image-698" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/690/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FREE .NET MVC 4 BETA Hosting Account with ASPHostCentral.com</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/688</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/688#comments</comments>
		<pubDate>Thu, 15 Mar 2012 03:54:56 +0000</pubDate>
		<dc:creator>George Veltreski</dc:creator>
				<category><![CDATA[Other Related Posts]]></category>
		<category><![CDATA[.net mvc 4 hosting]]></category>
		<category><![CDATA[asp.net mvc 4 hosting .net mvc 4.0 hosting]]></category>
		<category><![CDATA[asp.net mvc 4.0 hosting]]></category>
		<category><![CDATA[asphostcentral]]></category>
		<category><![CDATA[asphostcentral.com]]></category>
		<category><![CDATA[mvc 4.0 hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=688</guid>
		<description><![CDATA[<p>ASPHostCentral.com, the leader in ASP.NET and Windows Hosting Provider, proudly announces that we have supported the latest ASP.NET MVC 4.0 BETA Hosting.Â Â Â </p>
<p>To support Microsoft ASP.NET MVC 4.0 BETA Framework, we gladly inform you that we provide this beta account FREE of charge for a limited time (* terms and conditions apply).Â </p>
<p>
New Features in ASP.NET MVC 4</p>
<p>This <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/688">FREE .NET MVC 4 BETA Hosting Account with ASPHostCentral.com</a></span>]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://www.asphostcentral.com/ASPNET-MVC-4-Hosting.aspx">ASPHostCentral.com</a></strong>, the leader in ASP.NET and Windows Hosting Provider, proudly announces that we have supported the latest ASP.NET MVC 4.0 BETA Hosting.Â Â Â </p>
<p>To support Microsoft ASP.NET MVC 4.0 BETA Framework, we gladly inform you that we provide this beta account FREE of charge for a limited time (* terms and conditions apply).Â </p>
<p><a href="http://www.asphostcentral.com/ASPNET-MVC-4-Beta-Hosting.aspx"><img title="ASP.NET MVC 4.0 Beta Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2012/03/adsone_aspnet_mvc4_beta.gif" alt="" width="450" height="270" /></a><br />
<strong>New Features in ASP.NET MVC 4</strong></p>
<p>This section describes features that have been introduced in the ASP.NET MVC 4:Â<br />
- Enhancements to Default Project Templates<br />
- Better Support for Mobile Project Template<br />
- Enhancement in Display Modes<br />
- Mobile Project Template support for VB.NET<br />
- Dependency Injection Improvements Â Â Â </p>
<p><strong>Terms and Conditions in Using this ASP.NET MVC 4.0 BETA Account</strong>Â </p>
<p>The followings are the features you will get under this FREE ASP.NET MVC 4.0 BETA Account:Â<br />
- ASP.NET MVC 4.0 Beta Framework<br />
- 1 Website/Domain<br />
- 100 MB disk space<br />
- 100 MB bandwidth<br />
- 50 MB SQL 2008 space<br />
- 24/7 FTP access<br />
- Windows Server 2008 Platform</p>
<p>If you want to participate in this BETA program, there are several rules you need to understand:Â </p>
<p>- As this is a beta version, not all the features are available. They may be some issues on this beta framework, which will be fixed upon the full release of ASP.NET MVC 4.0 Framework</p>
<p>- ASPHostCentral.com does not guarantee the uptime of the sandbox solution. Additionally, we do not keep/store any backup of your files/accounts</p>
<p>- ASPHostCentral.com does not guarantee rapid response to any inquiries raised by a user</p>
<p>- This free account is only meant for testing. Users should not use it to store a production, personal, e-commerce or any blog-related site</p>
<p>- This free account is used to host any ASP.NET MVC 4.0 beta website only. Any questions that are not related to ASP.NET MVC 4.0 BETA will not be responded. A user shall not host any non-ASP.NET MVC 4.0 site on this free account either</p>
<p>- ASPHostCentral.com reserves full rights to terminate this beta program at any time. We will provide a notification on our Help Desk System prior to the termination of this program</p>
<p>- ASPHostCentral.com reserves full rights to terminate a user account, in which we suspect that there is an abuse to our system</p>
<p>- Once this beta program is terminated, your account will be completely wiped/remove from our system.</p>
<p>- This offer expires on <strong>31st May 2012</strong><br />
<strong><br />
If you wish to participate in this FREE ASP.NET MVC 4.0 BETA Program, you must register via <a href="https://secure.asphostcentral.com/BetaOrder.aspx">https://secure.asphostcentral.com/BetaOrder.aspx</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/688/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET 4.5 BETA Hosting with ASPHostCentral.com</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/686</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/686#comments</comments>
		<pubDate>Wed, 14 Mar 2012 04:33:46 +0000</pubDate>
		<dc:creator>George Veltreski</dc:creator>
				<category><![CDATA[Other Related Posts]]></category>
		<category><![CDATA[.net 4.5 beta hosting]]></category>
		<category><![CDATA[.net 4.5 hosting]]></category>
		<category><![CDATA[.net4.5 hosting]]></category>
		<category><![CDATA[asp.net 4.5 beta hosting]]></category>
		<category><![CDATA[asp.net 4.5 hosting]]></category>
		<category><![CDATA[asp.net4.5 hosting]]></category>
		<category><![CDATA[asphostcentral]]></category>
		<category><![CDATA[asphostcentral.com]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=686</guid>
		<description><![CDATA[<p>ASPHostCentral.com, the leader in ASP.NET and Windows Hosting Provider, proudly announces that we will support ASP.NET 4.5 Hosting.</p>
<p>To support Microsoft ASP.NET 4.5 Beta Framework, we gladly inform you that we provide this beta account FREE of charge for a limited time (* terms and conditions apply).</p>
<p></p>
<p>The followings are the features you will get under this FREE <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/686">.NET 4.5 BETA Hosting with ASPHostCentral.com</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.asphostcentral.com/ASPNET-45-Hosting.aspx">ASPHostCentral.com</a>, the leader in ASP.NET and Windows Hosting Provider, proudly announces that we will support ASP.NET 4.5 Hosting.</p>
<p>To support Microsoft ASP.NET 4.5 Beta Framework, we gladly inform you that we provide this beta account <strong>FREE of charge</strong> for a limited time (* terms and conditions apply).</p>
<p><a href="http://www.asphostcentral.com/ASPNET-45-Beta-Hosting.aspx"><img title="ASP.NET 4.5 BETA Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2012/03/adsone_aspnet45_beta.gif" alt="" width="450" height="270" /></a></p>
<p>The followings are the features you will get under this FREE ASP.NET 4.5 BETA Account: Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </p>
<p>- .NET 4.5 Beta Framework<br />
- 1 Website/Domain<br />
- 100 MB disk space<br />
- 100 MB bandwidth<br />
- 50 MB SQL 2008 space<br />
- 24/7 FTP access<br />
- Windows Server 2008 Platform</p>
<p>Â If you want to participate in this Beta program, there are several rules you need to understand: Â Â Â Â Â Â Â Â Â Â Â Â Â </p>
<p>- As this is a beta version, not all the features are available. They may be some issues on this beta framework, which will be fixed upon the full release of ASP.NET 4.5 Framework<br />
- ASPHostCentral.com does not guarantee the uptime of the sandbox solution. Additionally, we do not keep/store any backup of your files/accounts<br />
- ASPHostCentral.com does not guarantee rapid response to any inquiries raised by a user<br />
- This free account is only meant for testing. Users should not use it to store a production, personal, e-commerce or any blog-related site<br />
- This free account is used to host any ASP.NET 4.5 beta website only. Any questions that are not related to ASP.NET 4.5 beta will not be responded. A user shall not host any non-ASP.NET 4.5 site on this free account either<br />
- ASPHostCentral.com reserves full rights to terminate this beta program at any time. We will provide a notification on our Help Desk System prior to the termination of this program<br />
- ASPHostCentral.com reserves full rights to terminate a user account, in which we suspect that there is an abuse to our system<br />
- Once this beta program is terminated, your account will be completely wiped/remove from our system.<br />
- For details, please check <a href="http://www.asphostcentral.com/ASPNET-45-Beta-Hosting.aspx">http://www.asphostcentral.com/ASPNET-45-Beta-Hosting.aspx</a><br />
- This offer expires on 31st May 2012</p>
<p><strong>If you want to participate on this FREE ASP.NET 4.5 Beta Program, you must register via <a href="https://secure.asphostcentral.com/BetaOrder.aspx">https://secure.asphostcentral.com/BetaOrder.aspx</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/686/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 5 Hosting :: Combo Box Type Ahead in Silverlight 5</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/683</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/683#comments</comments>
		<pubDate>Wed, 14 Mar 2012 03:14:07 +0000</pubDate>
		<dc:creator>Mark Latchey</dc:creator>
				<category><![CDATA[Silverlight 5 Hosting]]></category>
		<category><![CDATA[cheap silverlight 5 hosting]]></category>
		<category><![CDATA[cheap silverlight hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[silverlight hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=683</guid>
		<description><![CDATA[<p>A nice, small feature in the new Silverlight 5 Beta is the ability to type ahead in combo boxes.</p>
<p></p>
<p>This makes choosing from long list far simpler.</p>
<p>You can see this at work by whipping up a very quick Silverlight 5 application.</p>

<p>On the Main page add a combo box,</p>
<p>&#60;Grid
x:Name="LayoutRoot"
Background="White"&#62;
&#60;ComboBox
x:Name="theComboBox"
Height="40"
Width="150"
Margin="20" /&#62;
&#60;/Grid&#62;</p>
<p>In the code behind weâ€™ll create some data to <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/683">Silverlight 5 Hosting :: Combo Box Type Ahead in Silverlight 5</a></span>]]></description>
			<content:encoded><![CDATA[<p>A nice, small feature in the new Silverlight 5 Beta is the ability to <em>type ahead</em> in combo boxes.</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_1.jpg"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_1.jpg" alt="" title="image_1" width="199" height="252" class="aligncenter size-full wp-image-684" /></a></p>
<p>This makes choosing from long list far simpler.</p>
<p>You can see this at work by whipping up a very quick Silverlight 5 application.</p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>On the Main page add a combo box,</p>
<p><code>&lt;Grid<br />
x:Name="LayoutRoot"<br />
Background="White"&gt;<br />
&lt;ComboBox<br />
x:Name="theComboBox"<br />
Height="40"<br />
Width="150"<br />
Margin="20" /&gt;<br />
&lt;/Grid&gt;</code></p>
<p>In the code behind weâ€™ll create some data to act as the ItemsDataSource for the combo box:</p>
<p><code>public MainPage( )<br />
{<br />
InitializeComponent( );<br />
List&lt;string&gt; contents = new List&lt;string&gt;<br />
{ "apples",<br />
"berries",<br />
"apple pie",<br />
"apple strudel",<br />
"blueberries",<br />
"strawberries",<br />
"cherries",<br />
"cherry pie",<br />
"bananas"};<br />
theComboBox.ItemsSource = contents;<br />
}</code></p>
<p>Thatâ€™s enough to see the effect. When you run the program the combo box comes up empty. Start typing apple strudel and youâ€™ll see that the combo box first finds apples, then apple pie (on the space) and then when you type the s, it finds apple strudel.</p>
<p>You can see this most clearly by rerunning the application and opening the combo box before you begin typing. You can then see the selected item move as you type (see image at top). Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/683/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 4 Hosting :: Customer IApplicationService for Silverlight Applications</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/673</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/673#comments</comments>
		<pubDate>Mon, 05 Mar 2012 04:09:34 +0000</pubDate>
		<dc:creator>Landon Ferguson</dc:creator>
				<category><![CDATA[Silverlight 4 Hosting]]></category>
		<category><![CDATA[cheap hosted silverlight 4]]></category>
		<category><![CDATA[cheap silverlight 4 hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[silverlight 4 hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=673</guid>
		<description><![CDATA[<p>In my experience working with Silverlight applications, probably one of the most underused features I&#8217;ve witnessed is the ability to abstract application-level functionality using the IApplicationService and IApplicationLifetimeAware interfaces. This, in turn, results in the over-use (and abuse) of the Startup and Exit events in the Application object. Before you get angry with me shaking a <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/673">Silverlight 4 Hosting :: Customer IApplicationService for Silverlight Applications</a></span>]]></description>
			<content:encoded><![CDATA[<p>In my experience working with Silverlight applications, probably one of the most underused features I&#8217;ve witnessed is the ability to abstract application-level functionality using the IApplicationService and IApplicationLifetimeAware interfaces. This, in turn, results in the over-use (and abuse) of the Startup and Exit events in the Application object. Before you get angry with me shaking a finger, I&#8217;ll admit I&#8217;ve done this quite a bit myself.</p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p><strong>IApplicationService</strong></p>
<p>The IApplicationService interface allows you to define a class that is part of the overall application lifecycle. It provides a mechanism to create a service that lasts the duration of a Silverlight application. It is called once when the application starts with an ApplicationServiceContext, and called again when the application ends.</p>
<p>One of the most useful things you can do with this service class is use it to intelligently parse parameters passed to the Silverlight application. How many times have you found yourself hooking into the application startup and then parsing these out? What&#8217;s worse, in larger, complex applications, many different portions of the application share responsibility for handling these parameters. It breaks the concept of loose coupling to have a single front-end parsing it out and then stuffing it into an object to dole it out to the consumers that need it.</p>
<p>By implementing IApplicationService, you can create a service for your functionality that handles its own initialization parameters. There is no &#8220;central&#8221; place that has to understand everything. Silverlight supports using multiple application services, so you can have a logger service that looks at the logging parameter and a file upload service that looks at the file storage location parameter, so on and so forth.</p>
<p>Here&#8217;s what a service that handles writing to the debugger might look like:</p>
<p><code>public class LoggerService : IApplicationService<br />
{<br />
const string TRACE_LEVEL_KEY = "TraceLevel";</p>
<p>public LoggerService()<br />
{<br />
_traceLevel = TraceLevel.Warning; // default<br />
}</p>
<p>private TraceLevel _traceLevel;</p>
<p>public ILogger Logger { get; private set; }</p>
<p>public static LoggerService Current { get; private set; }</p>
<p>public void StartService(ApplicationServiceContext context)<br />
{<br />
Current = this;<br />
if (context.ApplicationInitParams.ContainsKey(TRACE_LEVEL_KEY))<br />
{<br />
_traceLevel = (TraceLevel)Enum.Parse(typeof (TraceLevel), context.ApplicationInitParams[TRACE_LEVEL_KEY], true);<br />
}</p>
<p>Logger = new CustomLogger(TraceLevel);<br />
Logger.WriteLine(TraceLevel.Information, "Logger service started.");<br />
}</p>
<p>public void StopService()<br />
{<br />
Logger.WriteLine(TraceLevel.Information, "Logger service stopped.");<br />
}<br />
}</code></p>
<p>This service now allows me to configure the logging level in the web page using initParams, like this:</p>
<p><code>&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"&gt;<br />
&lt;param value="ClientBin/MySilverlightApp.xap"/&gt;<br />
&lt;param value="onSilverlightError" /&gt;<br />
&lt;param value="TraceLevel=Warning" /&gt;<br />
&lt;param value="white" /&gt;<br />
&lt;param name="minRuntimeVersion" value="4.0.50401.0" /&gt;<br />
&lt;param value="true" /&gt;<br />
&lt;/object&gt;</code></p>
<p>What&#8217;s more, if it is in a project by itself, adding the service to a new application is so simple it&#8217;s hard to believe more people don&#8217;t take advantage of this. After referencing the project, I won&#8217;t have to mangle my App.xaml.cs and hook into any events in order to use the new service, parse out parameters, etc. Nope, I just add a simple reference to it in the App.xaml that looks like this:</p>
<p><code>&lt;Application.ApplicationLifetimeObjects&gt;<br />
&lt;MySilverlightApp:LoggerService/&gt;<br />
&lt;/Application.ApplicationLifetimeObjects&gt;</code></p>
<p><strong>IApplicationLifetimeAware</strong></p>
<p>Now, if you really want to do some cool things, you can extend the class even further by implementing IApplicationLifetimeAware. This will give you four additional methods: Starting, Started, Exiting, and Exiting.</p>
<p>Use these to perform set up and clean up actions.</p>
<p>For example, in the <a href="http://sterling.codeplex.com/" target="_blank">Sterling Windows Phone 7 Example</a> I wrote (Sterling is an open source object-oriented database for Silverlight 4.0 and Windows Phone 7) I created a database service to make it easy to set up and tear down the database engine. The service looks like this:</p>
<p><code>public class DatabaseService : IApplicationService, IApplicationLifetimeAware<br />
{<br />
public static DatabaseService Current { get; private set; }</p>
<p>public ISterlingDatabaseInstance Database { get; private set; }</p>
<p>private SterlingEngine _engine;</p>
<p>public void StartService(ApplicationServiceContext context)<br />
{</p>
<p>Current = this;<br />
_engine = new SterlingEngine();<br />
}</p>
<p>public void StopService()<br />
{<br />
_engine = null;<br />
}</p>
<p>public void Starting()<br />
{<br />
_engine.Activate();<br />
Database = _engine.SterlingDatabase.RegisterDatabase&lt;PhoneDatabase&gt;();<br />
}</p>
<p>public void Started()<br />
{<br />
return;<br />
}</p>
<p>public void Exiting()<br />
{<br />
_engine.Dispose();<br />
}</p>
<p>public void Exited()<br />
{<br />
return;<br />
}<br />
}</code></p>
<p>As you can see, I am managing everything that would normally get hooked into the application startup and exit events. Instead of adding to that code-behind, however, I can abstract these hooks in a re-usable component that is easily dropped into or out of the App.xaml as needed. Just like the previous example, the only thing needed to hook into the database in a Windows Phone 7 application is now just this:</p>
<p><code>&lt;Application.ApplicationLifetimeObjects&gt;<br />
&lt;SterlingExample:SterlingService/&gt;<br />
&lt;/Application.ApplicationLifetimeObjects&gt;</code></p>
<p>The Silverlight framework guarantees my service is called to start only once, so I take advantage of that call to assign a static property. That way, anywhere in the application I need to reference the service, I can use ServiceName.Current (for example, SterlingService.Current).</p>
<p>Don&#8217;t limit yourself to just that, however. One common task in composite Silverlight applications is &#8220;bootstrapping&#8221; objects. If you are using the Managed Extensibility Framework (MEF), you may need to configure some catalogs and then call the CompositionInitializer. You can do this in an application service as well. In fact, many of my applications have nothing in the App.xaml.cs code behind except a call to InitializeComponent. Why? Because I can set the root visual in a service, like this:</p>
<p><code>[Import]<br />
public Shell MainShell { get; set; }</p>
<p>public void StartService(ApplicationServiceContext context)<br />
{<br />
_myCatalog = new AggregateCatalog(new DeploymentCatalog());<br />
var container = new CompositionContainer(_mainCatalog);<br />
CompositionHost.Initialize(container);<br />
CompositionInitializer.SatisfyImports(this);<br />
}</p>
<p>public void Starting()<br />
{<br />
Application.Current.RootVisual = MainShell;<br />
}</code></p>
<p>When called, the service sets up the catalogs/containers/etc. and satisfies imports to generate the shell. If the shell has any dependencies, these are also handled by MEF. Then, in the starting method, we wire the shell to the root visual because this is called just before the full visual tree is loaded.</p>
<p>I hope to see this powerful feature used more often to add some quality customer service to Silverlight applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/673/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 4 Hosting :: Data Contracts and Behaviors over the Wire Silverlight 4</title>
		<link>http://www.silverlighthostingnews.com/index.php/archives/669</link>
		<comments>http://www.silverlighthostingnews.com/index.php/archives/669#comments</comments>
		<pubDate>Thu, 01 Mar 2012 03:21:33 +0000</pubDate>
		<dc:creator>Landon Ferguson</dc:creator>
				<category><![CDATA[Silverlight 4 Hosting]]></category>
		<category><![CDATA[cheap hosted silverlight 4]]></category>
		<category><![CDATA[cheap silverlight 4 hosting]]></category>
		<category><![CDATA[HostForLife]]></category>
		<category><![CDATA[HostForLife.eu]]></category>
		<category><![CDATA[silverlight 4 hosting]]></category>
		<category><![CDATA[silverlight hosting]]></category>
		<category><![CDATA[wcf ria hosting]]></category>

		<guid isPermaLink="false">http://www.silverlighthostingnews.com/?p=669</guid>
		<description><![CDATA[<p>One feature I employ often in Silverlight projects is the ability to share a model between the client and the server. When you expose a model using a WCF service, you can consume it on the Silverlight side and indicate you want to reuse types in a referenced assembly, rather than having the proxy types generated. <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.silverlighthostingnews.com/index.php/archives/669">Silverlight 4 Hosting :: Data Contracts and Behaviors over the Wire Silverlight 4</a></span>]]></description>
			<content:encoded><![CDATA[<p>One feature I employ often in Silverlight projects is the ability to share a model between the client and the server. When you expose a model using a WCF service, you can consume it on the Silverlight side and indicate you want to reuse types in a referenced assembly, rather than having the proxy types generated. At first glance this seems ideal because you can truly project behavior such as validation to the client without maintaining separate copies of the type in question. Upon further inspection, however, there can be some unexpected side effects.</p>
<div><a href="http://www.hostforlife.eu"><img class="aligncenter size-full wp-image-1065" title="European Windows Hosting" src="http://www.aspnethostingnews.com/wp-content/uploads/2011/12/ads_300x180.jpg" alt="" width="400" height="230" /></a></div>
<p>Consider the following class that is defined in a standalone Silverlight assembly but shared on the server by adding it as a linked file:</p>
<p><code>[DataContract]<br />
public class SimpleModel<br />
{<br />
public SimpleModel()<br />
{<br />
NonMemberProperty = "This was initialized within the constructor.";<br />
}</p>
<p>private string _field = "This is an initialized field.";</p>
<p>public string NonMemberProperty { get; set; }</p>
<p>[DataMember]<br />
public string MemberProperty { get; set; }</p>
<p>public string Field<br />
{<br />
get { return _field; }<br />
}<br />
}</code></p>
<p>I&#8217;ve purposefully packed a few different examples to help illustrate what is happening. It should be very clear what will happen when you instantiate the class. The field will be initialized to expose a value, the non-member will be given a value, and the member property (the one tagged as a data member) is initialized to the default value of null.</p>
<p>Now you can expose the model using a web service. Just add a new &#8220;Silverlight-enabled Web Service&#8221; to your web project, and give it a very simple operation to fetch a new instance of the model:</p>
<p><code>[ServiceContract(Namespace = "http://jeremylikness.com/examples/")]<br />
[SilverlightFaultBehavior]<br />
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br />
public class SimpleService<br />
{<br />
[OperationContract]<br />
public SimpleModel GetSimpleModel()<br />
{<br />
var simpleModel = new SimpleModel<br />
{<br />
MemberProperty = "This was initialized by the service."<br />
};<br />
return simpleModel;<br />
}<br />
}</code></p>
<p>What happens now? On the server, you&#8217;ll get a new object that now has three fully populated properties &#8211; the field (which returns the value initialized on the internal field), the non-member property, and the member property. So far, so good.</p>
<p>Flip over to the Silverlight client side. Create a grid that has rows and columns for the labels and the values. Embed an instance of the model like this:</p>
<p><code>&lt;Grid.DataContext&gt;<br />
&lt;Model:SimpleModel/&gt;<br />
&lt;/Grid.DataContext&gt;</code></p>
<p>And then you can easily data-bind the values like this:</p>
<p><code>&lt;TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Field}"<br />
Style="{StaticResource ValueStyle}"/&gt;<br />
&lt;TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding NonMemberProperty}"<br />
Style="{StaticResource ValueStyle}"/&gt;<br />
&lt;TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding MemberProperty}"<br />
Style="{StaticResource ValueStyle}"/&gt;</code></p>
<p>Add a button for the user to click. We&#8217;ll forget MVVM for now (heck, our model didn&#8217;t even implement property change notification) and just implement a code behind. Right now the model should create an instance in the designer and show you the two initialized fields â€” something like this:<br />
<a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_1.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_1.png" alt="" title="image_1" width="356" height="149" class="aligncenter size-full wp-image-670" /></a></p>
<p>If you do nothing in the code-behind you should still be able to run the application and see the initialized values. Now let&#8217;s get down to the wire.</p>
<p>Add a service reference, only make sure you specify that it re-uses types. You get to the dialog by clicking on the &#8220;advanced&#8221; button when adding a new service. It should look something like this:</p>
<p><a href="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_2.png"><img src="http://www.silverlighthostingnews.com/wp-content/uploads/2012/03/image_2.png" alt="" title="image_2" width="400" height="247" class="aligncenter size-full wp-image-671" /></a></p>
<p>This ensures that the service will return the actual type represented by the model, rather than generating a proxy type that lives in the namespace of the service itself. You get to have the full type with all of the methods and functions you&#8217;ve defined, even if they aren&#8217;t being sent over the wire. Now that&#8217;s handy, right?</p>
<p>In the code behind for the button click, simply fetch the instance generated on the server and update the data context:</p>
<p><code>private void Button_Click(object sender, RoutedEventArgs e)<br />
{<br />
((Button) sender).IsEnabled = false;<br />
var client = new ServiceReference.SimpleServiceClient();<br />
client.GetSimpleModelCompleted += _ClientGetSimpleModelCompleted;<br />
client.GetSimpleModelAsync();<br />
}</p>
<p>void _ClientGetSimpleModelCompleted(object sender, ServiceReference.GetSimpleModelCompletedEventArgs e)<br />
{<br />
btnLoad.IsEnabled = true;<br />
LayoutRoot.DataContext = e.Result;<br />
}</code></p>
<p>Not too complicated, right?</p>
<p>If you run the application and click the load button, the code-behind will call the service and fetch a new instance. When the instance is bound to the data context, however, you may notice something strange. The property that was flagged as a data member and was set on the server comes through just fine, but the other properties are empty. How can that be? Even though you didn&#8217;t tag them as data members, they should have been set when the type was constructed. The field property doesn&#8217;t even have a setter.</p>
<p>This is as expected, but what about the other two properties? The answer is well-documented but often overlooked. If you read the documentation for the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx" target="_blank">data contract serializer</a>, or the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.xmlobjectserializer.aspx" target="_blank">XML object serializer</a> that it is based on, you&#8217;ll find a small but important sentence that explains: &#8220;When instantiating the target object during deserialization, the DataContractSerializer does not call the constructor of the target object.&#8221; That explains the non-member property. When the serializers create the type, they by pass the normal type system. This makes sense because you are expecting to reconstruct the type based on the contract, so the properties not passed in the contract aren&#8217;t really relevant. The type is built from the ground-up by setting the properties that were serialized, but no other initialization code is called.</p>
<p>If you&#8217;re wondering about the field, it&#8217;s the same problem. While the C# language allows you to initialize fields as a convenience, the code is actually moved into the constructor for the type. If you decompile the DLL for the model used in this example, this is what the decompiled constructor will look like:</p>
<p><code>public SimpleModel()<br />
{<br />
this._field = "This is an initialized field.";<br />
base();<br />
this.NonMemberProperty = "This was initialized within the constructor.";<br />
}</code></p>
<p>As you can see, the compiler conveniently moved the field initialization into the constructor. All of the initialized fields will be called from the start of the constructor before calling into the base object constructor and then handling the code you specify.</p>
<p>So what&#8217;s the point? It is very important that you understand the implications of sharing types between the server and the client, especially when there are behaviors you are expecting. If you have certain properties that are initialized in the constructor, you can&#8217;t expect them to be available when addressing the instances on the client. One way to deal with this is to move initialization logic into a separate method and call it from the constructor but expose it so you can call it elsewhere as well. This may work in some cases but often the reason for putting code into the constructor is to hide the implementation details of how the type is initialized from the consumer. If that&#8217;s the case, it&#8217;s probably better to make sure all of your exposed properties and methods handle initialization appropriately without a dependency on the constructor. For example, remove the initialization code for the field and replace the property code with this:</p>
<p><code>get { return _field ?? (_field = "This was initialized in the getter."); }</code></p>
<p>Now the field will be initialized on first access and never initialized again, but it will work equally well regardless of how it is instantiated. Another way to keep the initialization details private is to track the initialization state with a private field. Booleans default to false so the field will have that value whether the type was created with a call to its constructor or not. Your code can check the value of this field and call the initialization logic the first time it is needed.</p>
<p>Sharing types between the client and the server is a powerful feature that Silverlight provides. It is important that you understand the nuances of how it works so that you can construct your classes to behave consistently and don&#8217;t fall victim to unexpected behaviors on the client because the constructors were never called for your types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlighthostingnews.com/index.php/archives/669/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

