2015-05-06 88 views
-1
[OperationContract] 
public List<Drug> GetAll_Drug() 
{ 
    List<Drug> obj_Lst_t; 
    using (var ctx = new EpriscriptionContext()) 
    { 
     obj_Lst_t = ctx.Drug.ToList(); 
    } 
    return obj_Lst_t; 
    } 

得到答案enter image description here ------但添加OperationContract的得到錯誤返回數據時得到錯誤wcf?

調試 enter image description here 獲取返回的數據錯誤 enter image description here

+0

什麼問題?它在哪裏發生? ...你想讓我們對此做些什麼? – Ben

回答

0

按照您的堆棧跟蹤的屏幕

System.ServiceModel.Channels.HttpCha nnelUtilities.ProcessGetResponseWebException

所以我相信這可能是由於延遲加載或EF代理序列化。

嘗試禁用代理。

[OperationContract] 
public List<Drug> GetAll_Drug() 
{ 
    List<Drug> obj_Lst_t; 
    using (var ctx = new EpriscriptionContext()) 
    { 
     ctx.Configuration.ProxyCreationEnabled = false; // disable proxy creation here. 
     obj_Lst_t = ctx.Drug.ToList(); 
    } 
    return obj_Lst_t; 
} 
+0

坦克。爲什麼從OperationContract GetAll_Drug沒有錯誤? – user1039134

+0

@ user1039134對不起!沒有得到你所問的? –

-1

YOE moust刪除使用,

[OperationContract] 
public List<Drug> GetAll_Drug() 
{ 
    List<Drug> obj_Lst_t; 
    var ctx = new EpriscriptionContext(); 

     ctx.Configuration.ProxyCreationEnabled = false; 
     obj_Lst_t = ctx.Drug.ToList(); 
} 
+1

這不是一個好的答案,絕對不是最好的做法,只是「刪除使用」沒有明確處置。 –

0

時返回數據CTX處置, 然後obj_Lst_t值轉換爲null, 或使用:

[OperationContract] 
public List<Drug> GetAll_Drug() 
{ 
    List<Drug> obj_Lst_t; 
    using (var ctx = new EpriscriptionContext()) 
    { 
     ctx.Configuration.ProxyCreationEnabled = false; 

foreach(var data in ctx.Drug) 
     { obj_Lst_t.add(data);} 
    } 
    return obj_Lst_t; 
} 

或使用:

[OperationContract] 
    public List<Drug> GetAll_Drug() 
    { 
     List<Drug> obj_Lst_t; 
     using (var ctx = new EpriscriptionContext()) 
     { 
      ctx.Configuration.ProxyCreationEnabled = false; 

    foreach(var data in ctx.Drug) 
      { obj_Lst_t.add(new Drug{...});} 
     } 
     return obj_Lst_t; 
    } 
0

通過添加以下代碼錯誤

[OperationContract] 
public List<Patients> GetAll_Patients() 
{ 
List<Patients> obj_Lst_t; 
using (var ctx = new EpriscriptionContext()) 
{ 
ctx.Configuration.ProxyCreationEnabled = false; 
obj_Lst_t = ctx.Patients.ToList(); 
} 
return obj_Lst_t; 
} 

enter image description here