Silverlight 3 Tools Issue: New WCF Template is Broken by Silverlight 2 SDK
In Silverlight 3, we’ve introduced support for binary message encoding for WCF services, which should give a performance boost. Silverlight 2, as you may recall, only supports basicHttpBinding. The new binding is the default for Silverlight-enabled WCF services created with the Silverlight 3 Tools.
If you’ve upgraded from the Silverlight 2 Tools for Visual Studio to the Silverlight 3 Tools for Visual Studio, you may run into the following warnings when adding a reference to a newly created WCF service (i.e. using the new template in Silverlight 3 Tools):
If you continue to run your Silverlight application, it will throw an exception when you try to instantiate a client for your service. The stack trace will look like the following:
The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client() at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard) at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName) at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory() at System.ServiceModel.EndpointTrait`1.CreateChannelFactory() at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase`1..ctor() at Somewhere.In.Your.Silverlight.Application()
This is caused by a bug where the Microsoft.Silverlight.ServiceReference.dll assembly is loaded into VS from the Silverlight 2 SDK instead of the Silverlight 3 SDK. Since Silverlight 3 adds support for binary encoding in WCF services, when you add a service reference to such a service using the Silverlight 2 assembly it fails and the generated ServiceReferences.ClientConfig is non-functional.
To work around this issue for now, uninstall the Silverlight 2 SDK, update your service reference, and rebuild your Silverlight application.
If you want your service to be consumable by both Silverlight 2 and Silverlight 3 applications, you can change the binding back to basicHttpBinding. To do that, edit the web.config file for the web project containing the service. Then update the service reference and rebuild your Silverlight application.