Skip to main content

Microsoft Silverlight

Answered Question error message "The given key was not present in the dictionary" when using WCF service with silverlightRSS Feed

(0)

joydeepsen
joydeepsen

Member

Member

6 points

34 Posts

error message "The given key was not present in the dictionary" when using WCF service with silverlight

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


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


joydeepsen
joydeepsen

Member

Member

6 points

34 Posts

Re: error message "The given key was not present in the dictionary" when using WCF service with silverlight

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.

Thanks in advance

Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


Mog Liang - MSFT
Mog Lian...

All-Star

All-Star

15894 points

1,541 Posts

Answered Question

Re: error message "The given key was not present in the dictionary" when using WCF service with silverlight

Open Web.config in your website, find this line

<serviceHostingEnvironment aspNetCompatibilityEnabled="false" />

set aspNetCompatibilityEnabled="false"

you can get more help from this link

How to: Build a Service for Silverlight Clients

Mog Liang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

vitthalgb
vitthalgb

Member

Member

30 points

21 Posts

Re: Re: error message "The given key was not present in the dictionary" when using WCF service with silverlight

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. 

dhavalmania27
dhavalma...

Member

Member

13 points

22 Posts

Re: Re: error message "The given key was not present in the dictionary" when using WCF service with silverlight

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


 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities