Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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()
        {
            //get the selected table
            ExchangeTable selectedTable = comboTable.SelectedItem as ExchangeTable;
            NameValue selectedLanguage = comboSelectLanguage.SelectedItem as NameValue;
            //call the ws to get the table fields
            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
Posted
Updated 7-Jul-15 11:19am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900