Click here to Skip to main content
15,888,984 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 
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 
Yes, I am not using the VS generated proxy. I create the proxy like this:

public ISyncData GetProxy()
{
NetTcpBinding tcpBinding = new NetTcpBinding();
EndpointAddress endPoint = new EndpointAddress("net.tcp://Victor-PC:8000/HelloWorldEndPoint");

return ChannelFactory<ISyncData>.CreateChannel(tcpBinding, endPoint);
}


Then in the host I have a method like this:

IEnumerable<MyData> GetData()
{
....
}

And the client receive the data. But there are sometimes when I receive the "socket connection aborted." error message. I don't think it is due because of this though because I have changed the return parameter to MyData[] or List<MyData> and I keep on getting the error.

I read that when you manually create the proxy then the return parameter is List<T>, but if you create the proxy using VS then there is an option to indicate how the collection will be return either array or list.

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.