I have Silverlight application that retrieves data from the database through a WCF Service. What my application have to do is to display the referent data anytime a button gets MouseOvered. I did it in a way that that when a button gets MouseOvered, I called my service and retrieved the data, but it generetad a big delay. Now, I think that another way should be making a list of all objects from the table, and just searching the id in the list when the action is triggered. I started coding, but it resulted in fail (and such an ugly piece of code).
My Working Code
private void MouseOverHarbor(object sender, RoutedEventArgs e)
{
Ellipse thisPath = (Ellipse)sender;
DataRetrieverReference.DataRetrieverClient webService = new DataRetrieverReference.DataRetrieverClient();
webService.GetDataCompleted += new EventHandler<DataRetrieverReference.GetDataCompletedEventArgs>(webService_GetDataCompleted);
webService.GetDataAsync(Convert.ToInt32(thisPath.DataContext));
}
void webService_GetDataCompleted(object sender, WebPortos.DataRetrieverReference.GetDataCompletedEventArgs e)
{
NameField.Text = e.Result.Name;
CityField.Text = e.Result.City;
StateField.Text = e.Result.State;
CompanyField.Text = e.Result.Company;
}
What I tried to do
private List<vwPortos_SEP> harborList;
private int counter;
public Brasil()
{
InitializeComponent();
this.harborList = new List<vwPortos_SEP>();
DataRetrieverClient webService = new DataRetrieverClient();
webService.GetCounterCompleted += new EventHandler<GetCounterCompletedEventArgs>(webService_GetCounterCompleted);
webService.GetCounterAsync();
webService.GetDataCompleted += new EventHandler<DataRetrieverReference.GetDataCompletedEventArgs>(webService_GetDataCompleted);
for (int i = 0; i < counter; i++)
{
webService.GetDataAsync(i);
}
}
void webService_GetDataCompleted(object sender, WebPortos.DataRetrieverReference.GetDataCompletedEventArgs e)
{
MessageBox.Show("It works!");//It doesn't work!
try
{
this.harborList.Add(e.Result);
}
catch (Exception exc)//It doesn't even throw ecxpetions, this method is never reached.
{
MessageBox.Show(exc.Message);
MessageBox.Show(exc.InnerException.Message);
}
}
Maybe I'm missing something really big, but my webService_GetDataCompleted
method is never reached.
Thanks in advance folks!