I’m confused. I’ve got a Silverlight project that currently runs and displays a list of servers from my mocked model (I am following the MVVM pattern).
The interface is coded as follows:
public class GetServersCompletedEventArgs : EventArgs { public Exception Error {get; set;} public IEnumerable<LicenseServer> Results {get; private set;} public GetServersCompletedEventArgs(Exception error, IEnumerable<LicenseServer> results) { this.Error = error; this.Results = results; } } public delegate void GetServersCompletedEvent(GetServersCompletedEventArgs e); public interface IDataService { void GetServers(); event GetServersCompletedEvent GetServersCompleted; }
As you can see the CompletedEventArgs return the results as a IEnumerable.
The problem that I am having is defining <LicenseServer> in such a way that I can stub it with fake data or populate the results from real data (ala ado.net data services).
I’ve created a local class LicenseServer but the service always returns a different type of LicenseServer.
I get an error:
convert Unable to cast object of type ‘DataServiceOrderedQuery[LicenseMon.LMonServiceReference.License_Server]’ to type ‘System.Data.Services.Client.DataServiceQuery`1[LicenseMon.Model.LicenseServer]
Which I read as LicenseServer from the service reference cannot be converted over to the LicenseServer I’ve defined in my model class
Why am I having trouble? Shouldn’t I be able to develop my classes independently and be able to switch between a live database and my internally generated data? Am I approaching this the wrong way?
Any code samples, explanations, links etc would be most helpful
Often, when consuming a web resource (SOAP, WCF or ADO.NET Data Services), a separate client proxy class is generated. This will have similar layout, but has no automatic conversion to your local type. Some systems support type re-use (WCF etc), but not all.
You could add a conversion or an interface to the partial class; but in general, you should treat this as a separate type.