Page view counter
How to call wcf service from silverlight class library to get result and call that class function from xaml page Subscribe to this thread
Last post 12-24-2008 5:18 AM by mahendra.gurav. 2 replies.
Sort Posts:
12-24-2008 12:54 AM
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

mahendra.gurav

Loading...
Joined on 07-29-2008
Pune
Posts 152
12-24-2008 5:02 AM
Marked as Answer
Re: How to call wcf service from silverlight class library to get result and call that class function from xaml page

The code will never work as you have done it.  You would have to have some way to notify the user the data is back.  Maybe you could raise an event when the data is returned

Silverlight-help
Vb Tips
Space Coast .Net User Group

ken tucker

Loading...
Joined on 12-23-2003
Port St. John, Florida
Posts 1,776
12-24-2008 5:18 AM
Re: Re: How to call wcf service from silverlight class library to get result and call that class function from xaml page

Hi,

  Thnaks for replying. Please give any sample related to this.

 

Thanks,

Mahendra

mahendra.gurav

Loading...
Joined on 07-29-2008
Pune
Posts 152
Microsoft Communities