This article shows how to develop configuration-less WCF Services for Silverlight client.
It is pretty complex to maintain the configuration part of WCF services, if more services are adding / modifying, very frequently.
It will be a better idea to develop a service library for our Silverlight client, without any configurations in the config file. The following class diagram says about such a library, which is the scope of this article.
Using the Code
The vital class in the above class diagram is
SLServiceHost, which inherits from
ServiceHost and overrides
ApplyConfiguration method. There, you can implement our custom bindings and Meta data behaviour, MEX, etc.
Below is the code snippet:
protected override void ApplyConfiguration()
There is a custom service host factory,
SLServiceHostFactory, which inherits from
ServiceHostFactoryBase and creates the instance of our
In our custom service(MyService.svc), in the XAML, we set the factory and service code behind attributes as follows:
<%@ ServiceHost Language="C#"
Silverlight.Services.Web application from VS2010. The port is set to
Now run your
wcftestclient utility from VS command prompt and add the service and test.
Points of Interest
- Service Library with no configuration in Web.Config
- Single Contract Interface,
- 13th September, 2010: Initial post