2012-04-27 116 views
2

這是來自此處的跟進問題:linq issue with creating relationships關於我收到的答案。林不知道什麼happend,但我得到一個錯誤:底層連接已關閉:接收時發生意外錯誤

The underlying connection was closed: An unexpected error occurred on a receive. 

而且這是在異常情況發生:

string uriGroup = "http://localhost:8000/Service/Group"; 
    private void ListGroups_Click(object sender, RoutedEventArgs e) 
    { 
     XDocument xDoc = XDocument.Load(uriGroup); // this line 
     var groups = xDoc.Descendants("Group") 
      .Select(n => new 
      { 
       GroupName = n.Element("GroupName").Value, 
       GroupHeader = n.Element("GroupHeader").Value, 
       TimeCreated = DateTime.Parse(n.Element("TimeAdded").Value), 
       Tags = n.Element("Tags").Value, 
       Messages = n.Element("GroupMessages").Value 
      }) 
      .ToList(); 

     dataGrid2.ItemsSource = groups; 
    } 
+1

[Enabled tracing](http://msdn.microsoft.com/en-us/library/ms733025.aspx)?沒有?這樣做,你會看到詳細的錯誤:) – Reniuz 2012-04-27 08:17:05

+0

這是託管在一個控制檯應用程序,所以不認爲這會工作。 – 2012-04-27 08:20:55

+0

如果您通過瀏覽器訪問URL uriGroup,您看到了什麼? – dash 2012-04-27 08:21:41

回答

10

因爲你是返回對象的List,很可能你已經超過MaxItemsInObjectGraph。您可以通過修改你的web.config(或app.config)中增加值:

<behaviors> 
    <behavior> 
     <dataContractSerializer maxItemsInObjectGraph="6553600" /> 
    </behavior> 
</behaviors> 

您也可以考慮看秋後算賬:

  • <readerquota>
  • MaxReceivedMessageSize
  • MAXBUFFERSIZE
  • MaxBufferPoolSize

您應該啓用WCF Tracing,因爲它將包含更詳細的錯誤。是的,即使對於自主託管的應用程序也是如此。

+2

@Downvoter,對於我的回答,我會很感激建設性的批評,這樣我可以在未來提供更好的質量回應。請分享你的想法和意見。 – Tung 2012-04-27 08:35:32