2010-06-25 14 views
0

嘗試從WCF服務返回數據時收到此錯誤消息。 。套接字連接被中止。可能的SerializationException?

「套接字連接被中止這可能是由錯誤處理遠程主機,或底層網絡資源問題被超過你的消息或接收超時導致本地套接字超時是'00:00: 「59.9960000'」

這是誤導,因爲它顯示約59秒,但發生異常約2秒。上一次我收到這個錯誤消息時,它必須處理由序列化實體框架對象造成的無限循環。幸運的是,我剛剛做出了改變,所以很容易發現。

這次我不知道是什麼改變了原因。我分析了實體框架類以發現沒有任何更改。據我所知,數據庫也保持不變,雖然我不知道如何證明,因爲它相當大。

如果我用調試器遍歷WCF代碼,我發現它正確地收集數據。它甚至試圖返回信息。但是,在客戶端代理我收到這行代碼的異常:

return Channel.GetDocuments(user, criterion);

沒有任何人有任何見解或工具,可以幫助我追查這個異常?

回答

1

我發現這個問題。它必須處理從數據庫中刪除的列,並且實體框架模型未被更新。這不是我以前想過的循環。

這是一個把我指向正確方向的技巧。

客戶端代理

public List<ImageData> GetDocuments(User user, DocumentSearchCriterion criterion) 
{ 
    Channel.GetDocuments(user, criterion); 
} 

WCF端服務

public List<ImageData> GetDocuments(User user, DocumentSearchCriterion criterion) 
{ 
    List<ImageData> documents = new DocumentRepository().GetDocuments(user, criterion); 

    // Temporary test to see if we can serialize the data. This is only for debugging 
    // purposes and needs to be removed from production code. 
    DataContractSerializer serializer = new DataContractSerializer(documents.GetType()); 
    using(FileStream stream = new FileStream("SerializerOutput.xml", FileMode.Create)) 
    { 
     // This line will give an exception with useful details while debugging. 
     serializer.WriteObject(stream, documents); 
    } 

    return documents; 
} 

希望幫助別人用這個通用的和誤導性的例外。

0

檢查以下內容:

  1. 你有大量的數據,所以你需要在你的config文件
  2. 最有可能在我的經驗,延長超時是,你必須在類型循環引用你從WCF函數返回。

,所以如果你有一個具有這樣的一類,WCF會不高興

[DataContract] 
public class MyClass 
{ 
    public ChildObject(int i) 
    { 
    } 

    [DataMember] 
    public MyClass Parent 
    { 
     get; 
     set; 
    } 
} 
+0

我也懷疑這是一個循環引用。你有一個聰明的方式來找出哪個「DataMember」是罪魁禍首?我瀏覽過這些房產,沒有任何「顯而易見」的東西正在跳出來。 – 2010-06-25 18:35:52

+0

我尋找兩件事情.... 1.一個與調用者類型相同的返回類型。 2.這通常是它的一個屬性,它是一個具有屬性的類,其中一個類與對象圖中某個父類的屬性類型相同。儘管我的頭頂沒有任何技巧,但我知道。 – 2010-06-25 18:54:17