Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #44: Silverlight-enabled WCF Services versus ASMX Web Services

In Tip of the Day #42 I talked about how to create and use a web service using WCF for your Silverlight application. For this tip I would like to briefly discuss WCF and some highlights on why you should use it over the traditional ASMX based Web Services. Also, I will be touching on what Silverlight-enabled WCF services gives you.

Highlights and Advantages of WCF:

  • WCF stands for “Windows Communication Foundation”.
  • WCF is Microsoft’s next generation platform for network distributed services that shipped as part of the .NET 3.0 framework. Call it the successor and unifier of most distributed systems out there today.
  • WCF runtime resides under the System.ServiceModel namespace.
  • In most cases WCF is significantly more performant (25%-50%) faster. See this MSDN article for comparisons.
  • The throughput of WCF is inherently scalable from a single processor to a quad processor.
  • The WCF model unifies the feature wealth of ASMX, WSE, Enterprise Services, MSMQ, and Remoting. This way, developers only have to master a single programming model.
  • WCF can be hosted in IIS Servers, Windows services and standalone apps like windows forms, console apps.
  • WCF provides a DataContractSerializer which allows complex data types and private attributes to be serialized and sent.
  • WCF can have messages sent in a variety of channels including HTTP, TCP, MSMQ, Named pipe, etc.

The list goes on but hopefully this gives you a good starting point into why you should use WCF over traditional web services.

When adding a WCF service to your web site for Silverlight, make certain to choose “Silverlight-enabled WCF service” over the standard “WCF Service”. Since WCF is the best practice for writing services with Silverlight, Microsoft has provided this template as a way to get you a service that is already configured in a specific way for Silverlight. Primarily what is done for you is:

  1. Web.config is configured to use basicHttpBinding since Silverlight does not support ws*.
  2. ASP compatibility mode: <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

Thank you,
--Mike Snow

 Subscribe in a reader

Comments

Microsoft Weblogs said:

In Tip of the Day #42 I talked about how to create and use a web service using WCF for your Silverlight

# September 22, 2008 3:33 PM

2008 September 23 - Links for today « My (almost) Daily Links said:

Pingback from  2008 September 23 - Links for today &laquo; My (almost) Daily Links

# September 23, 2008 7:37 AM

Silverlight news for September 23, 2008 said:

Pingback from  Silverlight news for September 23, 2008

# September 23, 2008 9:24 AM

figuerres said:

what about using Silverlight with WCF TCP ??

# September 23, 2008 12:37 PM

Dew Drop - September 23, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - September 23, 2008 | Alvin Ashcraft's Morning Dew

# September 23, 2008 3:24 PM

Mike Snows Tipp des Tages #43, #44 und #45 at Blog von J??rgen Ebner said:

Pingback from  Mike Snows Tipp des Tages #43, #44 und #45 at Blog von J??rgen Ebner

# September 25, 2008 3:24 AM

Silverlight news for September 25, 2008 said:

Pingback from  Silverlight news for September 25, 2008

# September 25, 2008 10:58 AM

Visual Web Developer Team Blog said:

Silverlight Tip of the Day #46 Title: Font Support in Silverlight Silverlight Tip of the Day #45: Title:

# September 25, 2008 1:55 PM

anyeone said:

A comment/question regarding the speed of WCF services being called from Silverlight - is there any known issue with this being particularly slow when running in the VS2008 debugger?

I have a web project that exposes a Silverlight enabled WCF service with a handful of OperationContracts that currently are returning hard coded, very small results (usually either a single value or a few light objects defined in DataContracts with only a couple properties (usually an integer id and a string description).

The solution has a Silverlight application project in it, and it includes a service reference to the WCF service in it.  

The problem - the callbacks from the WCF service are taking 10 seconds!  Even though they aren't actually accessing a database and are just returning simple data.

An example:

   [OperationContract]

   public int GetDocumentCount(int someIdIWillUseEventuallyButNotNow)

   {

       ///TODO:  Implement me instead of passing back nonsense.

       return DateTime.Now.Second;

   }

takes 10 seconds!

I have worked with WCF from ASP.NET and have never had the callbacks be so slow, even with real data access occurring.

Any ideas?

# October 9, 2008 10:52 AM

mike.snow said:

anyeone -

Hi, I just tried out your scenario and I had 0 seconds go by when making the WCF call.

I then tried it with milliseconds and I got 123 milliseconds go by, which is about what I would expect.

Might be an issue on your machine.

# October 9, 2008 8:06 PM

Coreys|Portfolio.com said:

Twin Cities Code Camp Source

# October 16, 2008 12:53 AM

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the

# January 2, 2009 5:57 PM

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the

# January 2, 2009 5:57 PM

o UAU nosso de cada dia said:

essa lista eu copiei desse blog bárbaro (acompanhe por RSS você também): uma lista de dicas super úteis

# January 3, 2009 6:26 AM