Hi friends,
i am learner in WCF and I have a problem with calling a wcf service function from a xaml page.I am trying to call it asynchonously from my xaml page. The function (getTableFields) returns a list of datatables that i bind to a grid view in wpf.
This is how i call the method.
private void GetFields()
{
ExchangeTable selectedTable = comboTable.SelectedItem as ExchangeTable;
NameValue selectedLanguage = comboSelectLanguage.SelectedItem as NameValue;
DatabaseManagementService.DatabaseManagementServiceClient proxy = new DatabaseManagementService.DatabaseManagementServiceClient();
proxy.Endpoint.Address = new System.ServiceModel.EndpointAddress(Common.DatabaseManagementServiceAddress);
proxy.GetTableFieldsCompleted += new EventHandler<DatabaseManagementService.GetTableFieldsCompletedEventArgs>(proxy_GetTableFieldsCompleted);
proxy.GetTableFieldsAsync(selectedTable.ExchangeDbLogicalName, selectedTable.LogicalName, true, selectedLanguage.Value);
}
void proxy_GetTableFieldsCompleted(object sender, DatabaseManagementService.GetTableFieldsCompletedEventArgs e)
{
if (Common.WebServiceException(e.Error))
return;
if (e.errorCode == 0)
{
dataGridFields.ItemsSource = e.Result;
}
}
Now i need to store the list of datatables that i get from the wcf method getTableFields() in another global variable and use it for my purpose.
How to do it ?
For example, i need something like below:
list of<datatables> originalfields = new list of<datatables>(); //declared globally in my xaml page
originalfields = GetTableFields(...); //coming from the service
I tried to call GetFields() on a button click like this:
GetFields();
changedFields = GetChangedFields(originalfields,dataSource);
again but the proxy_GetTableFieldsCompleted event is getting executed at the end of the button click event and hence originalfields is always null AND I get a null reference error when i try to use it. Please help me as am struck with it the whole day.
Thanks in advance