客户端服务引用不工作ToArray

时间:2014-01-21 14:17:21

标签: c# web-services

我正在尝试与我的客户解决此问题 我收到错误:无法将类型'DentistServiceReference.Dentist []'隐式转换为'DentistServiceReference.DentistServiceClient []'

以下是代码:

private List<DentistServiceReference.DentistServiceClient> DentistDetail()
{
    DentistServiceReference.DentistServiceClient client = new 
    DentistServiceReference.DentistServiceClient();

    DentistServiceReference.DentistServiceClient[] dentists = client.DentistDetail();  <== error

    return dentists.ToList();

我也尝试更改client.DentistDetail()。ToArray但仍然有错误。

无法将方法组'ToArray'转换为非委托类型'DentistServiceReference.DentistServiceClient []'。你打算调用这个方法吗?

我进入App_WebReferences,右键单击Add Service Reference,Discover选择我的DentistService.svc,转到Advanced选项卡,然后在Collection Type:System.Array下,我应该将它更改为system.collections.generic.list吗?我也看到了System.Collections.ArrayList你能解释一下我的问题有什么区别和解决方法?非常感谢

这是DentistService.cs

 public class DentistService : IDentistService
 {
 /*   public List<Dentist>  DentistDetail()    */    use to be like this before the change
    public List<DentistServiceReference.Dentist> DentistDetail()
    {
        using (DentistDataContext db = new DentistDataContext())
        {
            return (from dentist in db.Dentists

                select new  Dentist()    
                {
                    Id = dentist.Id,
                    Dentist_name = dentist.Dentist_name
                }).ToList();     <=== error after the change
    }
}

}

0 个答案:

没有答案