找不到ServiceClient [来自元数据]

时间:2014-01-20 20:17:44

标签: c# asp.net wcf

我正在尝试修复此WCF服务以填充下拉列表。我得到的唯一问题是我找不到DoctorDetail [来自元数据],这是假设要生成的。以下是Apointement.aspx.cs的代码

private List<DoctorServiceReference.DoctorServiceClient> DoctorDetail()
{
    DoctorServiceReference.DoctorServiceClient client = new 
    DoctorServiceReference.DoctorServiceClient();

    DoctorServiceReference.DoctorServiceClient[] doctors = client.**DoctorDetail()**; **<== error

    return doctors.ToList();
}
  

错误如下:错误4'MedicServiceReference.DoctorServiceClient'不包含'DoctorDetail'的定义,并且没有扩展方法'DoctorDetail'接受类型'DoctorServiceReference.DoctorServiceClient'的第一个参数可以找到(你是否遗漏了) using指令或程序集引用?)C:\ Users \ SP_Admin \ Documents \ Visual Studio 2013 \ WebSites \ Doctor \ pages \ Apointement.aspx.cs 189

DoctorService.cs WebService

public class DoctorService : IDoctorService
{
    public List<Doctor>  DoctorDetail()    

    {
        using (DoctorDataContext db = new DoctorDataContext())
        {
            return (from doctor in db.Doctors

                select new  Doctor()    
                {
                    Id = doctor.Id,
                    Doctor_name = doctor.Doctor_name
                }).ToList();
        }
    }
}

doctor.cs

public class DoctorDetail
{
    private int id;
    private string doctor_name;

    public DoctorDetail()
    {

    }

    public int Id { get { return this.id; } set { this.id = value; } }
    public string Doctor_name { get { return this.doctor_name; } set { this.doctor_name = value;   
    } }

}

我正在添加DoctorServiceClient [来自元数据]

namespace DoctorServiceReference
{
    [DebuggerStepThrough]
    [GeneratedCode("System.ServiceModel", "4.0.0.0")]
    public class DoctorServiceClient : ClientBase<IDoctorService>, IDoctorService
    {
        public DoctorServiceClient();
        public DoctorServiceClient(string endpointConfigurationName);
        public DoctorServiceClient(Binding binding, EndpointAddress remoteAddress);
        public DoctorServiceClient(string endpointConfigurationName, EndpointAddress 
               remoteAddress);
        public DoctorServiceClient(string endpointConfigurationName, string remoteAddress);

        public Doctor[] DoctorDetail();
        public Task<Doctor[]> DoctorDetailAsync();
    } 
}

3 个答案:

答案 0 :(得分:0)

纯粹是猜测,但看起来DoctorServiceReference.DoctorServiceClient指的是由Visual Studio中的“添加服务引用”或SvcUtil.EXE实用程序生成的类。尝试类似:List<DoctorServiceReference.DoctorDetail>作为列表类型。生成的代理可能位于DoctorServiceReference命名空间中。

答案 1 :(得分:0)

服务方法是 public List DoctorDetail()

来自客户端代理的调用是 DoctorServiceReference.DoctorServiceClient [] doctors = client.DoctorDetail()

答案 2 :(得分:0)

问题是我无法生成更新Web /服务参考。我关闭VS中的所有内容并重新打开它。然后我就能够执行更新Web /服务参考。 ServiceClient元数据就在那之后。