Home > WCF > WCF client-proxies cannot consume values of type IEnumerable!

WCF client-proxies cannot consume values of type IEnumerable!

February 23rd, 2011 Nizar Leave a comment Go to comments

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. 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.

Kick It on DotNetKicks.com Shout it
  1. janaranjan
    March 16th, 2011 at 14:18 | #1

    Nizar,

    Even it is not possible to return IList from WCF.

  2. March 18th, 2011 at 16:46 | #2

    Yea, because IList inherits from IEnumerable.

  3. JW
    March 28th, 2011 at 10:32 | #3

    IEnumerable CAN be returned from a WCF service method.

  4. March 28th, 2011 at 11:01 | #4

    Did you use VS to generate the proxies? If so, take a look at the generated code and you’ll notice that VS converted the IEnumerables to arrays.

  5. JW
    March 28th, 2011 at 12:52 | #5

    @Nizar
    Your title states that WCF return values cannot be of type IEnumerable – which they can be. Client proxy classes not being able to consume an IEnumerable is a different issue.

  6. March 28th, 2011 at 13:10 | #6

    Thanks for pointing that out! I’ll consider renaming the title.

  7. March 28th, 2011 at 13:16 | #7

    @JW: Title renamed and content edited. Thanks for your suggestion!

  1. No trackbacks yet.