代码之家  ›  专栏  ›  技术社区  ›  netmajor

尝试在Silverlight应用中使用WCF服务时出错

  •  0
  • netmajor  · 技术社区  · 15 年前

    我在Silverlight应用程序中出错:

         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)
    

    当我按下按钮时它就出现了。此操作导致使用wcf服务:

    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;
            }
    

    当我在控制台应用程序中使用服务时,一切正常,但在SL中我有错误:/ 你知道吗?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Ozan HELPY    15 年前

    当你的查询似乎说你只得到一个孩子(Dziecko=child,no)时,你确定你得到了一个列表吗

    也许你应该把e.Result投给Dziecko:

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

    但正如David所说,我们需要InnerException来查看出了什么问题。

    推荐文章