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.