2014-01-20 41 views
-1

我想修復此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(); 
    } 
} 

回答

0

純粹是猜測,但它看起來像DoctorServiceReference.DoctorServiceClient是指將被添加會產生一類Service Studio中的Service Reference或SvcUtil.EXE實用程序。嘗試像這樣:List<DoctorServiceReference.DoctorDetail>作爲列表類型。生成的代理很可能位於DoctorServiceReference名稱空間中。

+0

我終於可以通過退出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

+0

您是否看到有什麼問題? – user3127986

0

服務方法是 公共列表DoctorDetail()

和從客戶機代理呼叫是 DoctorServiceReference.DoctorServiceClient []醫生= client.DoctorDetail()

+0

我終於可以通過退出Visual Studio來更新Web/Services並重新打開它。我右鍵點擊App_WebReferences來更新Web /服務引用。錯誤仍然存​​在,並且錯誤消息是錯誤\t 2不能將類型'DoctorServiceReference.Doctor []'隱式轉換爲'DoctorServiceReference.DoctorServiceClient []'C:\ Users \ SP_Admin \ Documents \ Visua l Studio 2013 \ WebSites \ DoctorApt \ pages \ Apointement.aspx.cs - – user3127986

0

問題是我無法生成更新Web /服務引用。我關閉VS中的所有內容並重新打開它。那麼我能夠執行更新Web /服務參考。 ServiceClient元數據在那之後。