views:

39

answers:

1

I have error in Silverlight app:

     An exception occurred during the operation, making the result invalid.  
Check InnerException for exception details.

       at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
       at SecretaryAppNav.ServiceReference1.GetChildByFirstnameCompletedEventArgs.get_Result()
       at SecretaryAppNav.Views.FindChild.client_GetChildByFirstnameCompleted(Object sender, GetChildByFirstnameCompletedEventArgs e)
       at SecretaryAppNav.ServiceReference1.Service1Client.OnGetChildByFirstnameCompleted(Object state)

It appears when I push the button. This action cause consuming the wcf service:

private void button1_Click(object sender, RoutedEventArgs e)
        {
            //BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
            //EndpointAddress endpointAddress = new EndpointAddress("http://localhost:15371/Service1.svc");
            //IService1 personService = new ChannelFactory<IService1>(basicHttpBinding, endpointAddress).CreateChannel();
            //personService.BeginGetChildByFirstname(this.tbChildName.Text, 
            //    delegate(IAsyncResult result)
            //{
            //    IList<Dziecko> p = ((IService1)result.AsyncState).EndGetChildByFirstname(result);
            //    this.Dispatcher.BeginInvoke(
            //        delegate()
            //        {
            //            this.tbChildSurname.Text = p.ElementAtOrDefault<Dziecko>(0).Nazwisko;
            //        }
            //    );
            //}, personService);
            Service1Client client = new Service1Client();
            client.GetChildByFirstnameCompleted += new EventHandler<GetChildByFirstnameCompletedEventArgs>(client_GetChildByFirstnameCompleted);
            client.GetChildByFirstnameAsync(this.tbChildName.Text.ToString());
        }

        void client_GetChildByFirstnameCompleted(object sender, GetChildByFirstnameCompletedEventArgs e)
        {
            this.dataGridChild.DataContext = (IList<Dziecko>)e.Result;
        }

When I consume service in console app everything works ok, but in SL i have errors :/ Any idea ?

A: 

Are you sure you get a List when your query seems to say that you only get one child (Dziecko = child, no?)

Maybe you should cast e.Result to Dziecko:

this.dataGridChild.DataContext = (Dziecko)e.Result;

But as David says, we need the InnerException to see what goes wrong.

Ozan