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.
Comments
Anonymous
March 18, 2009
PingBack from http://www.clickandsolve.com/?p=25063Anonymous
March 18, 2009
With the release of Silverlight 3 Beta, you’ll may want to try out the new features. Unfortunately, SilverlightAnonymous
March 27, 2009
I saw this warning. Do you know why? Warning 1 The element cannot contain white space. Content model is empty. D:AzureSilverlightApplication1SilverlightApplication1ServiceReferences.ClientConfig 7 99 SilverlightApplication1 Warning 2 The element 'httpTransport' cannot contain child element 'extendedProtectionPolicy' because the parent element's content model is empty. D:AzureSilverlightApplication1SilverlightApplication1ServiceReferences.ClientConfig 8 26 SilverlightApplication1 <configuration> <system.serviceModel> <bindings> <customBinding> <binding name="CustomBinding_Service1"> <binaryMessageEncoding /> <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"> <extendedProtectionPolicy policyEnforcement="Never" /> </httpTransport> </binding> </customBinding> </bindings> <client> <endpoint address="http://localhost:63165/Service1.svc" binding="customBinding" bindingConfiguration="CustomBinding_Service1" contract="ServiceReference1.Service1" name="CustomBinding_Service1" /> </client> </system.serviceModel> </configuration>Anonymous
March 27, 2009
Gary, I think it's due to the section: <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"> <extendedProtectionPolicy policyEnforcement="Never" /> </httpTransport> Can you try removing the <extendedProtectionPolicy> element and making the <httpTransport> element self-closing? I haven't figured out what causes this to be generated incorrectly yet.Anonymous
March 27, 2009
It works. Thank you very much for help.Anonymous
March 28, 2009
Thank you very much for this post. I spend 10hr on a single problem (i never spent this much time on a single issue to solve) and I was stuck where no matter what i do i get "The remote server returned an error: NotFound" WebException. After reading your post i uninstall silverlight 2.0 sdk then remove and added the WCF service back and the error went away and project is working fine.Anonymous
May 03, 2009
i have removed SL 2 SDK.But my app not showing the output. whatever i am returning from service is not collecting into the SL app. my code is as follows--> Service.vb Imports System.ServiceModel Imports System.ServiceModel.Activation <ServiceContract(Namespace:="")> _ <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _ Public Class Service1 <OperationContract()> _ Public Function DoWork() Dim db As EMPDataClassesDataContext = New EMPDataClassesDataContext() Return db.EMPs.Where(Function(emp) emp.EMPSAL > 0) ' Add your operation implementation here End Function ' Add more operations here and mark them with <OperationContract()> End Class page.xaml.vb Imports WebServiceApp.ServiceReference1 Partial Public Class MainPage Inherits UserControl Public Sub New() InitializeComponent() Dim proxy As ServiceReference1.Service1Client = New ServiceReference1.Service1Client() AddHandler proxy.DoWorkCompleted, AddressOf proxy_DoWorkCompleted proxy.DoWorkAsync() 'proxy.CloseAsync() End Sub Private Sub proxy_DoWorkCompleted(ByVal sender As Object, ByVal e As ServiceReference1.DoWorkCompletedEventArgs) grdEmp.ItemsSource = e.Result End Sub End Class but when iam debugging the code the proxy_DoWorkCompleted Method is not invoking.so there is no chance to obtain returned result from service.so what could be the problem? please help me. Thanks in advance.Anonymous
June 09, 2009
I'm having this same issue, but I am on an install that has never had any SL2 installed.Anonymous
September 11, 2009
have the same problem, uninstall of sdk 2, rebuild and re-reference does not fix it. I think the problem is caused by my ServiceReferences.ClientConfig being (almost) empty, it only contains: "<configuration/>" That problem is discussed here: http://forums.silverlight.net/forums/t/61600.aspx of the three solutions given, 2 of them dont work and the third one is difficult (filling it manually) if you dont know what the content should be (I am still learning)Anonymous
February 03, 2010
The comment has been removedAnonymous
February 03, 2010
SL2 was never installed on my machine before.Anonymous
April 29, 2010
The comment has been removedAnonymous
November 15, 2010
Has anybody found a solution? I'm on SL4 and Visual Studio 2010. I keep getting the same error: My client config seems fine; the web service shows up in IE; 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)......................