Reputation: 1735
Hello and thanks in advance for you help. I am working with a silverlight application using a WCF service. I have a service contract with three operation contracts: GetModuleObjects(), GetServerObjects(), and GetMonitorGroupObjects(), which retrieve modules, servers, and server groups respectively from a database. I have code which adds three events to the Service Client instance in Main. The first two events are firing correctly, but for some reason the code in the third event is never being reached, which is a problem. My code in Main.xaml.cs is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightTreeviewTest.ServiceReference1;
using System.Collections.ObjectModel;
namespace SilverlightTreeviewTest
{
public partial class MainPage : UserControl
{
static public ObservableCollection<ModuleObject> TableModuleObjects = new ObservableCollection<ModuleObject>();
static public ObservableCollection<ServerObject> TableServerObjects = new ObservableCollection<ServerObject>();
static public ObservableCollection<ServerGroupOCollection> TableMonitorGroupObjects = new ObservableCollection<ServerGroupOCollection>();
public MainPage()
{
InitializeComponent();
Service1Client MyWebService = new Service1Client();
MyWebService.GetModuleObjectsCompleted += new EventHandler<GetModuleObjectsCompletedEventArgs>(MyWebService_GetModuleObjectsCompleted);
MyWebService.GetModuleObjectsAsync();
}
void MyWebService_GetModuleObjectsCompleted(object sender, GetModuleObjectsCompletedEventArgs e)
{
dataGrid1.ItemsSource = e.Result;
foreach (DataTest_ModuleObject item in e.Result)
{
ModuleObject module = new ModuleObject((string)item.ModuleName,(int)item.ModuleStatus,(int)item.ServerID,(int)item.ID);
TableModuleObjects.Add(module);
}
Service1Client WebServiceForServers = new Service1Client();
WebServiceForServers.GetServerObjectsCompleted += new EventHandler<GetServerObjectsCompletedEventArgs>(WebServiceForServers_GetServerObjectsCompleted);
WebServiceForServers.GetServerObjectsAsync();
}
void WebServiceForServers_GetServerObjectsCompleted(object sender, GetServerObjectsCompletedEventArgs e)
{
//get each server entry from table and create ServerObject for each
//find the modules from the module collection then add server to server collection
foreach (DataTest_ServerObject item in e.Result)
{
ServerObject server = new ServerObject((string)item.ServerName,(int)item.ID,(int)item.Group_Id);
server.FindModules(TableModuleObjects);
TableServerObjects.Add(server);
}
//fire event to retrieve Monitor groups from db and assign servers to them
Service1Client WebServiceForGroups = new Service1Client();
WebServiceForGroups.GetMonitorGroupObjectsCompleted += new EventHandler<GetMonitorGroupObjectsCompletedEventArgs>(WebServiceForGroups_GetMonitorGroupObjectsCompleted);
WebServiceForGroups.GetServerObjectsAsync();
}
void WebServiceForGroups_GetMonitorGroupObjectsCompleted(object sender, GetMonitorGroupObjectsCompletedEventArgs e)
{
//get each MonitorGroup entry from table and create MonitorGroupObject(ServerGroupOCollection) for each
//find associated servers and then add the group to the collection of groups
foreach (DataTest_MonitorGroupObject item in e.Result)
{
ServerGroupOCollection mGroup = new ServerGroupOCollection((string)item.MonitorGroup_Name, (int)item.ID, (int)item.MonitorGroup_Type);
mGroup.FindServers(TableServerObjects);
TableMonitorGroupObjects.Add(mGroup);
}
}
}
}
I don't understand why the third event is never being fired and its code never reached. Please help!
Upvotes: 0
Views: 398
Reputation: 2320
In WebServiceForServers_GetServerObjectsCompleted you are registering an EventHandler for GetMonitorGroupObjectsCompleted but then invoking the GetServerObjectsAsync method.
Surely you mean to invoke GetMonitorGroupObjectsAsync (or similar).
Upvotes: 4