Thursday, July 8, 2010

Reusable Silverlight service project to avoid multiple addition on same WCF services reference

Inspiration of this post: http://forums.silverlight.net/forums/t/190515.aspx

We can create a reusable  Silverlight service project so that it can be used by different Silverlight application and service reference update will be restricted on a single place.

Suppose we have two Silverlight application that will use the common service:
1. SLProject1
2. SLProject2

Lets create a common service project:
Add new project of type 'Silverlight Class Library' suppose name is MyCommonWCFService like below:


In the MyCommonWCFService project add the service reference like below:


Now in your SLProject1 and SLProject2:
Add MyCommonWCFService project reference like below:


And also add the reference of System.ServiceModel:


Now copy the ServiceReferences.ClientConfig from the MyCommonWCFService project and add as existing item to the SLProject1 and SLProject2.

Example solution explorer will be like below:

Suppose we have a WCF service like below:


You can consume the common service client in SLProject1 or SLProject2 like below:




You can download the sample example.

No comments:

Post a Comment