我想修復此WCF服務來填充下拉列表。我得到的唯一問題是我無法找到假設要生成的DoctorDetail [來自元數據]。下面是從Apointement.aspx.cs找不到ServiceClient [來自元數據]
private List<DoctorServiceReference.DoctorServiceClient> DoctorDetail()
{
DoctorServiceReference.DoctorServiceClient client = new
DoctorServiceReference.DoctorServiceClient();
DoctorServiceReference.DoctorServiceClient[] doctors = client.**DoctorDetail()**; **<== error
return doctors.ToList();
}
錯誤代碼是下面的:錯誤4「DoctorServiceReference.DoctorServiceClient」不包含關於「DoctorDetail」的定義和沒有擴展方法「DoctorDetail」接受可找到類型爲'DoctorServiceReference.DoctorServiceClient'的第一個參數(是否缺少使用指令或程序集引用?)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();
}
}
我終於可以通過退出Visual Studio更新Web/Services並重新打開它。我右鍵點擊App_WebReferences來更新Web /服務引用。錯誤仍然存在,並且錯誤消息是錯誤無法將類型'DoctorServiceReference.Doctor []'隱式轉換爲'DoctorServiceReference.DoctorServiceClient []'\t C:\ Users \ SP_Admin \ Documents \ Visual Studio 2013 \ WebSites \ DoctorApt \ pages \ Apointement.aspx.cs – user3127986
您是否看到有什麼問題? – user3127986