Skip to main content
Home Forums Silverlight Programming Programming with .NET - General error message "The given key was not present in the dictionary" when using WCF service with silverlight
4 replies. Latest Post by dhavalmania27 on September 4, 2009.
(0)
joydeepsen
Member
6 points
34 Posts
03-11-2009 1:39 AM |
Hi members,
I was trying to integrate a asmx(asp.net 2.0) web service with my silverlight 2 application.But i was getting an error and till now i have not got any sollution.
So, i decided to move from simple asmx(asp.net 2.0) to WCF Service.
The steps i followed,
1. Created a Silverlight application with Visual Studio 2008 silverlight application template and by default it has created a test web application for me.
So far so good.
2. In the second step i have added a new WCF service using FIle-->Add-->New Web Site-->WCF service
3. I have added the WCF service reference to my silverlight project using Add Service reference.
3. Now after adding all the required namespace i wrote the code in my page.xmal.cs file like below,
public Page() { InitializeComponent(); ServiceClient client = new ServiceClient(); }
Now ServiceClient client = new ServiceClient(); line of code is throwing the exception,
The given key was not present in the dictionary
Note: I have created the service using filesystem and not HTTP.
Members, kindly help me out regarding that.
Thanks in advance
03-11-2009 2:16 AM |
HI members,
I have solved the problem but got another problem.
Actually i did not mention anything into the ServiceReferences.ClientConfig file and it was empty.
Now i have mentioned the bindings and client in the file and that previous error gone.
But now i am getting a new error saying "The remote server returned an error: NotFound"
The location of the error is,
Reference.cs and the function is,
public string EndSayHello(System.IAsyncResult result) { object[] _args = new object[0]; string _result = ((string)(base.EndInvoke("SayHello", _args, result))); return _result; }
The blocked line is throwing the exception.
Any suggestion members.
Mog Lian...
All-Star
15894 points
1,541 Posts
03-12-2009 11:31 PM |
Open Web.config in your website, find this line
<
set aspNetCompatibilityEnabled="false"
you can get more help from this link
How to: Build a Service for Silverlight Clients
vitthalgb
30 points
21 Posts
04-30-2009 7:53 AM |
i am getting the error "The given key was not present in the dictionary".
i have created database app in silverlight 3.iam using silverlight enabled WCF and LINQ to SQL Class.but iam getting the above error in Page.Xaml.vb at the bold line below
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Try Dim proxy As ServiceReference1.Service1Client = New ServiceReference1.Service1Client() AddHandler proxy.DoWorkCompleted, AddressOf proxy_DoWorkCompleted proxy.DoWorkAsync() proxy.CloseAsync() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
The stackTrace is-->
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 WCFDemo.ServiceReference1.Service1Client..ctor() at WCFDemo.MainPage.btnShow_Click(Object sender, RoutedEventArgs e)
My "ServiceReferences.ClientConfig" is also empty.
what should i do to come out of this error.i stucked here since last two days.
please help me.
Thanks in advance.
dhavalma...
13 points
22 Posts
09-04-2009 2:41 AM |
Hi,
Even i was getting this error. But i was using Silverlight 3. For me it was generating ServiceReferences.ClientConfig as empty.
then i changed the binding in the config file to basicHttpBinding in the <endpoint> element as shown below.
<endpoint address ="" binding="basicHttpBinding" contract="WebServiceLibrary.ICustomService">
and it worked fine for me :)
Regards,
Kalashnikov