Reputation: 388
I don't understand how to fix this issue. I will need your help and explanation on how to fix it.
I used a WebService to populate a DropDownList with artist names.
Here is the code behing.
private List<ArtistServiceReference.ArtistServiceClient> ArtistDetail()
{
ArtistServiceReference.ArtistServiceClient client =
new ArtistServiceReference.ArtistServiceClient();
ArtistServiceReference.Artist[] artists = client.ArtistDetail();
return artists.ToList(); <=== errror here
Cannot implicitly convert type System.Collections.Generic.List<ArtistServiceReference.Artist>
to System.Collections.Generic.List<ArtistServiceReference.ArtistServiceClient>
Here is the ArtistService.cs
public class ArtistService : IArtistService
{
public List<Artist> ArtistDetail()
{
using (ArtistDataContext db = new ArtistDataContext())
{
return (from artist in db.Artists
select new Artist()
{
Id = artist.Id,
Artist_nom = artist.Artist_nom
}).ToList();
}
}
}
Upvotes: 0
Views: 91
Reputation: 388
here is the solution:
code behind.cs
private List<ArtistServiceReference.Artist> ArtistDetail()
{
ArtistServiceReference.ArtistServiceClient client = new
ArtistServiceReference.ArtistServiceClient();
ArtistServiceReference.Voiture[] artists = client.ArtistDetail();
return artists.ToList();
}
ArtistService.cs
public class ArtistService : IArtistService
{
public List<Artist> ArtistDetail()
{
using (ArtistDataContext db = new ArtistDataContext())
{
return db.Artists.ToList();
}
}
}
Upvotes: 0
Reputation: 363
Your return type on your method should be a list of ArtistServiceReference.Artist as opposed to a list of ArtistServiceReference.ArtistServiceClient. You want to return a list of Artists by using the ArtistServiceClient, you are not returning a list of the clients.
private List<ArtistServiceReference.Artist> ArtistDetail()
{
ArtistServiceReference.ArtistServiceClient client =
new ArtistServiceReference.ArtistServiceClient();
var artists = client.ArtistDetail();
return artists.ToList();
}
Upvotes: 1
Reputation: 172270
If you want your client method to return a list of Artist
s, why do you declare it as returning a list of ArtistClient
s?
The following should fix your issue:
private List<ArtistServiceReference.Artist> ArtistDetail()
{
...
return artists.ToList();
}
or, even more elegant:
using YourNamespace.ArtistServiceReference;
private List<Artist> ArtistDetail()
{
...
return artists.ToList();
}
Upvotes: 1