Second Stanza

June 19, 2010

WCF Client Functionality and Silverlight

Filed under: Silverlight, WCF — dfbaskin @ 10:22 pm

I’ve been looking into Windows Communications Foundation (WCF) functionality, specifically focusing on client features for .NET and Silverlight clients, as a foundation for creating business applications.

So why wouldn’t I just use the WebClient or HttpWebRequest classes? These classes are simple to understand and use. And they don’t introduce the complexity of the WCF framework.

This is true, of course, but WCF offers flexibility that business applications require to implement additional management and interoperability features. Specifically, WCF offers a host of extensibility points that business applications can make use of, such as custom validation, service logging, and data manipulation.

This flexibility is also important where business applications have to rely on outside services. Third-party REST and SOAP services are more ubiquitous and integrating with these services is a common business requirement. These services are a "black box" and your application must manage change that is beyond your control.

Here are a few links to information related to WCF client functionality:

So I hope to post some code examples soon exploring some aspects of WCF client programming.


Sequential Asynchronous Workflows in Silverlight Using Rx Framework

Filed under: .NET Development, Rx Extensions, Silverlight — Tags: , — dfbaskin @ 4:44 pm

Jeremy Likness has an excellent post called Sequential Asynchronous Workflows in Silverlight using Coroutines. It seems like this example would also work well using the Reactive (Rx) Extensions Framework.

Here’s the source for an Rx handler of the RandomNumberService:

        /// <summary>
        ///     Once we have the references, start the workflow (the Reactive Way!)
        /// </summary>
        public void OnImportsSatisfied()
            int alpha = 0, red = 0, green = 0, blue = 0;

            int[] maxValuesRequired = new int[]{ 128, 255, 255, 255 };
            var colorWorkflow =
                    .ToObservable( maxValuesRequired )
                    .SelectMany( m =>
                            .FromAsyncPattern<int, int>(
                                ( maxValue, callback, state ) => {
                                    GetRandomNumberResult asyncResult = new GetRandomNumberResult();
                                    Service.GetRandomNumber( maxValue, v =>
                                        asyncResult.SetResult( v );
                                        callback( asyncResult );
                                    } );
                                    return asyncResult;
                                ( asyncResult ) => {
                                    return (int)asyncResult.AsyncState;
                            )( m )
            int colorIndex = 0;
                .Subscribe( result =>
                    switch( colorIndex++ )
                    case 0:
                        alpha = result + 128;
                    case 1:
                        red = result;
                    case 2:
                        green = result;
                    case 3:
                        blue = result;
                ex =>
                () =>
                    RectangleFill = new SolidColorBrush(
                        new Color
                            A = (byte)alpha,
                            B = (byte)blue,
                            G = (byte)green,
                            R = (byte)red
                        } );
                } );

I am wrapping the service call so that it follows the asynchronous service pattern, but this is the more common method of acessing services in a Silverlight application anyway.

Updated July 24, 2010:

I corrected the code by moving the setting of the RectangleFill property to the subscription’s completed method rather than in the Finally method. The latter is more designed for cleaning up after the subscription is completed.

Blog at