底层连接已关闭:接收时发生意外错误

底层连接已关闭:接收时发生意外错误

问题描述:

这是来自此处的跟进问题: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

因为你是返回对象的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