Click here to Skip to main content
15,889,116 members
Articles / Operating Systems / Windows

WCF client-proxies Cannot Consume Values of Type IEnumerable!

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Mar 2012CPOL 10.9K   3   3
A solution to this problem

So, I spent a few hours spinning my wheels trying to figure out why I’ve been getting the following exception:

[SocketException (0x2746): An existing connection was forcibly closed by
the remote host]
[IOException: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host.]
[WebException: The underlying connection was closed: An unexpected
error occurred on a receive.]
[CommunicationException: An error occurred while receiving the HTTP
response to http://myservice.mydomain.dk/MyService.svc. This could
be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by
the server (possibly due to the service shutting down). See server
logs for more details.]

Of the many reasons why you might see this exception, one is that the return value of a WCF service method cannot be of type System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<t>. If it is, then you’ll see the very informative and totally relevant (yes, I am being sarcastic) exception above when you try to consume the method on the client-side!

The solution of course is to change the service method definition to return an array.

This article was originally posted at http://nizarnoorani.com/index.php/archives/283

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NCube, Inc.
United States United States
Nizar Noorani is an independent software consultant. He provides services in the areas of web applications and systems architecture, analysis, design and development. Although proficient in a variety of technologies, he specializes in the .NET technology. He can be reached at nizar.noorani@gmail.com.

Comments and Discussions

 
QuestionThis is totally incorrect. Pin
Espiritu8-Jul-12 11:40
Espiritu8-Jul-12 11:40 
I have an operationContract that returns an IEnumerable<t> and it works fine. Other has the same IEnumerable and it fails. I changed the one that fails to use arrays and it fails again. I don't know what the problem is yet, but it is not caused by your opinion.
AnswerRe: This is totally incorrect. Pin
Nizar Noorani10-Jul-12 9:25
Nizar Noorani10-Jul-12 9:25 
GeneralRe: This is totally incorrect. Pin
Espiritu10-Jul-12 18:56
Espiritu10-Jul-12 18:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.