Skip to main content

Microsoft Silverlight

Answered Question How to call wcf service from silverlight class library to get result and call that class function from xaml pageRSS Feed

(0)

mahendra.gurav
mahendra...

Member

Member

136 points

158 Posts

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

Ken Tucker
Ken Tucker

All-Star

All-Star

16276 points

2,479 Posts

Answered Question

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

mahendra.gurav
mahendra...

Member

Member

136 points

158 Posts

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities