problems with WCF service calls

3 posts, 1 answers
  1. Rocio
    Rocio avatar
    16 posts
    Member since:
    Sep 2012

    Posted 04 Oct 2012 Link to this post

    Hello, I have a WCF Web Service, that makes a SQL query  to a data base and returns  a DataSet with the data.
    In my WPF browser app I have a gridView and it's ItemsSource is the DataSet that the service returns, at first I got this code:

      if (grid.ItemsSource == null)
      {
          //Creates the reference for the duplex Service
          InstanceContext instanceContext = new InstanceContext(new CallbackHandler());
          ServiceReference1.ServiceDuplexClient client2 = new ServiceDuplexClient(instanceContext);
           
          this.Cursor = System.Windows.Input.Cursors.Wait;
          //Call the service functon that returns the DataSet
          DataSet ds = client2.EventSummary();
          this.Cursor = System.Windows.Input.Cursors.Arrow;
     
          if (ds != null)
          {
              if (ds.DataSetName.Equals("OK"))
              {
                  //If it's OK the DataSet is the ItemsSource of the grid
                  grid.ItemsSource = ds;
              }
         }
    }

    It works fine, and does what it's supposed to do, the call to the service takes some moments, so I decided to change the cursor to a clock, but once I had it all working I like to change it for a busy indicator, so I added it to my code:

    <telerik:RadBusyIndicator x:Name="busyIndicator" BusyContent="Loading data...." Grid.ColumnSpan="3" Grid.RowSpan="3">

    a
    public partial class Page1 : Page
    {
       //Declare my background worker
        BackgroundWorker workerOperAct = new BackgroundWorker();
         
         public Page1()
         {
         InitializeComponent();
            workerOperAct.DoWork += this.WorkerOperActDoWork;
         workerOperAct.RunWorkerCompleted += WorkerOperActRunWorkerCompleted;
         }
         
         private void WorkerOperActDoWork(object sender, DoWorkEventArgs e)
        {
            //Create the reference for the service
            InstanceContext instanceContext = new InstanceContext(new CallbackHandler());
         ServiceReference1.ServiceDuplexClient client2 = new ServiceDuplexClient(instanceContext);
            //Call the service function that returns the DataSet
         DataSet ds = client2.EventSummary();
         if (ds != null)
         {
              if (ds.DataSetName.Equals("OK"))
                  {
                    grid.ItemsSource = ds;
                  }
          
    }
      }
        void WorkerOperActRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            grid.Visibility = Visibility.Visible;
               this.busyIndicator.IsBusy = false;
        }
        //More code....
    }

    It's the same code, and it should work, but when I try to call the service:
    DataSet ds = client2.EventSummary();

    I get an exception:
    An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in Unknown Module.
    Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

    If I remove the busy indicator and the background worker it works fine and I can't understand what's happening, I have no clue,
    I hope somebody can help me.
    Thanks!!

  2. Answer
    Yana
    Admin
    Yana avatar
    4593 posts

    Posted 09 Oct 2012 Link to this post

    Hello Rocio,

    I suggest to check this help article where we've explained how to integrate RadBusyIndicator with services.

    If this does not help, please send us a sample runnable project demonstrating exactly the exception.

    Regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Rocio
    Rocio avatar
    16 posts
    Member since:
    Sep 2012

    Posted 09 Oct 2012 Link to this post

    Hello Yana, thanks for your response, I have read that article and follow it from the begining and everything worked right, I don't know what the problem was, but thanks!!
Back to Top