There is a WCF service:
public List<Aktivy> Aktivy()
{
DataClassesDataContext db = new DataClassesDataContext();
var aktivy = from akt in db.Aktivys
select aktivy;
return aktivy.ToList();
}
Also there is a Silverlight client that accesses the WCF service:
private void Grid_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
ServiceReference.ServiceClient webService = new ServiceReference.ServiceClient();
webService.AktivyCompleted += new EventHandler<ServiceReference.AktivyCompletedEventArgs>(webService_AktivyCompleted);
webService.AktivyAsync();
}
void webService_AktivyCompleted(object sender, ServiceReference.AktivyCompletedEventArgs e)
{
}
How to convert e.Result (which features webService_AktivyCompleted) in the List<Aktivy> on the client side?
By default when you configure a service reference in Silverlight the collection types are set to deserialise into
ObservableCollection<T>(which is not aList<T>). If you always want a simpleList<T>you can modify the configuration of the service reference (right mouse on the service in Solution Explorer) and set collections to be represented asList<T>.However a better approach when dealing with these things is to work with interfaces instead of demanding a specific type. Modify your code to work with
IList<T>(aObservableCollection<T>implementsIList<T>) instead ofList<T>, this will work with any of the possible collection types that a service may be configured for.Since
ObservableCollection<T>is the most versatile of the available choices you would have to have a good reason why the collection must beList<T>. One reason might be because you are sharing code between server and client.