How to call wcf service from silverlight class library to get result and call that class function from xaml page
Hi,
Previously i call wcf serive directly from XAML page. wcf return list and i show it in datagrid in xaml page.It works fine.
Now i want to do different. I dont want to call wcf service directly from XAML page. Instead of this I take one Silverlight class liabrary in the same solutiona and service referesnce in that class liabrary. From the class liabrary i want to call the wcf service and in the Xaml want to call that class to get result.
My code is as below
page.Xaml code
SilverlightClassLibrary1.Class1 cls = new SilverlightClassLibrary1.Class1();
cls.getList();
dgResult.ItemsSource = cls.objCollection;
SilverlightClass Library code
namespace SilverlightClassLibrary1
{
public class Class1
{
public List<object> objList = new List<object>();
public ObservableCollection<procGetCompanyDetailsByIDResult> objCollection = new ObservableCollection<procGetCompanyDetailsByIDResult>();public void getList()
{
ServiceReference1.Service2Client sc = new Service2Client();
sc.GetCompListAsync();
sc.GetCompListCompleted += new EventHandler<GetCompListCompletedEventArgs>(sc_GetCompListCompleted);int cnt = objCollection.Count;
}
void sc_GetCompListCompleted(object sender, GetCompListCompletedEventArgs e)
{
objCollection = e.Result;
}
}
}
But objCollection returns zero in XAMl. I think its due to async call.
So please give solution. Also tell is it right way to do this. Here i want to create midddle tier to call wcf service. Dont want to call wcf service directly from XAML page.
Thanks,
Mahendra