Common WCF Exception : Connection Unexpectedly Closed

后端 未结 12 1033
耶瑟儿~
耶瑟儿~ 2021-02-05 17:19

I have three projects. One is a WCF Services Project, one is a WPF Project, and one is a Microsoft Unit Testing Project. I setup the WCF Services project with a data object th

相关标签:
12条回答
  • 2021-02-05 18:08

    I was getting this error when returning a large payload, it turned out to be the DataContractSerialiser stopping mid stream as it had hit the default maxItemsInObjectGraph setting, adding the folloing to my endpoint behavour fixed the problem

    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    
    0 讨论(0)
  • 2021-02-05 18:08

    I've noticed this when using LINQ and calls like Select, Where, etc. without an immediate call to .ToList() or ToArray(). Iterators will get you in trouble. They're not native types that WCF knows how to work with like List, Array, etc. They're of type WhereEnumerable or something. Just keep that in mind when sending back results from NHibernate or Entity Framework. Hope this helps someone. Took me hours to figure out.

    0 讨论(0)
  • 2021-02-05 18:09

    Make sure that nothing that isn't a FaultException gets thrown and passed back to the client.

    0 讨论(0)
  • 2021-02-05 18:09

    I could be way off, but it might be a security thing... I've gotten that error before, and I solved it... but I was up for days trying to get a lot of different bugs worked out.

    I have a sample article doing something basic, but I'm using net.tcp (with security set to "None") here: Duplex WCF Services Hosted in IIS Using Net.Tcp

    Also, where are you getting the error... is it on the ".Close()" line, or the ".GetTasks().ToString()" line?

    Another thing you can check is to simply telnet to localhost on port 9999 to see if the service is listening for incomming connections altogether.

    0 讨论(0)
  • 2021-02-05 18:10

    In my case my data contract had a [datamember] property that did not have a set method. I used a WCF trace to get the real error. https://stackoverflow.com/a/4271528/463425. I hope this helps someone.

    0 讨论(0)
  • 2021-02-05 18:13

    I Found the Answer

    Ok, not sure if it is kewl answering my own question, but here we go. For some reason the enumeration needed to be marked with the [EnumMember] Attributes as below:

    [DataContract]
    public enum Priority
    {
        [EnumMember]
        Low,
        [EnumMember]
        Medium,
        [EnumMember]
        High
    }
    

    Once I did that my tests and services could be called without the error occurring. I'm still not sure why that specific error was displayed. The error doesn't seem to align in any correlation with the functional reason the error occurred, but this fix definitely smoothed everything out.

    0 讨论(0)
提交回复
热议问题