This is a migrated thread and some comments may be shown as answers.

[Solved] Having trouble consuming Stored Procedures via WCF Data Service

1 Answer 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brad
Top achievements
Rank 1
Brad asked on 29 Oct 2010, 05:38 PM
Hi all,

I am new to XAML and Silverlight but I'm a bit confused why I'm seeing now what I'm seeing.

I've made a WCF Data Service, using Entity Data Model tied up to a SQL database. So far so good,

I can Discover the service and use the Entity as an object within my Silverlight application.

I have 2 questions, below is my code, based off Telerik examples.

#region

 

 

LoadData2 method

 

 

 

private void LoadData2()

 

{

 

 

BackgroundWorker worker = new BackgroundWorker();

 

worker.DoWork +=

 

new DoWorkEventHandler(worker_DoWork);

 

worker.RunWorkerCompleted +=

 

new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

 

worker.RunWorkerAsync();

}

#endregion

#region

 

 

worker_DoWork method

 

 

 

void worker_DoWork(object sender, DoWorkEventArgs e)

 

{

System.Windows.

 

Deployment.Current.Dispatcher.BeginInvoke(() =>

 

{

 

 

Uri uri = new Uri(String.Format("{0}/SearchPerson?lastName='{1}'",

 

svc.BaseUri, lastName),

 

UriKind.RelativeOrAbsolute);

 

svc.BeginExecute<

 

Employee_GetFirstName_Result>(uri, SearchPerson_Completed, null);

 

});

}

#endregion

#region

 

 

SearchPerson_Completed method

 

 

 

private void SearchPerson_Completed(IAsyncResult result)

 

{

data = svc.EndExecute<

 

Employee_GetFirstName_Result>(result).ToList();

 

 

 

this.RadGridView1.ItemsSource = data;

 

 

 

DispatcherTimer timer = new DispatcherTimer();

 

timer.Tick += OnTimerTick;

timer.Interval =

 

TimeSpan.FromSeconds(1);

 

timer.Start();

}

#endregion


#region

 

 

worker_RunWorkerCompleted event

 

 

 

void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

 

{

 

 

//this.RadGridView1.ItemsSource = data;

 

 

 

DispatcherTimer timer = new DispatcherTimer();

 

timer.Tick += OnTimerTick;

timer.Interval =

 

TimeSpan.FromSeconds(1);

 

timer.Start();

}

#endregion


First off, worker_RunWorkerCompleted fires off before SearchPerson_Completed has completed. And I'm sure thats just a newb question but I'm guessing it has something to do with it being aSync but don't know how to resolve it.

And secondly, I can browse the Uri in my browser (of my Stored Procedure) and see the data as expected but when I try to consume it in code my List comes back with 0 items.

Any help would be greatly appreciated.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Brad
Top achievements
Rank 1
answered on 29 Oct 2010, 09:10 PM
Well,

I decided to go RIA services instead of a WCF Data service. It fits my project more and works just as well.
Tags
GridView
Asked by
Brad
Top achievements
Rank 1
Answers by
Brad
Top achievements
Rank 1
Share this question
or