niao
niao

Reputation: 5070

The underlying connection was closed: The connection was closed unexpectedly

I have my wcf service and it runs fine. Then from my asp.net application I am trying to connect to this service. Everything is ok, request from asp.net is received in service (as I can debug code) and then when it returns to client I have the following error:

The underlying connection was closed: The connection was closed unexpectedly

My contract on WCF service is as follows:

[OperationContract()]
WCFResponseGetAllProducts GetAllProducts(WCFRequestGetAllProducts request);

And WCFResponseGetAllProducts , WCFRequestGetAllProducts classes have [DataContract] attributes. Members of those classes have [DataMember] attribute.

However when I added another method to my contract:

[OperationContract()]
int Test();

then I can execute it from asp.net mvc application without a problem. Can someone please help me? PS. I host my wcf service in default web server in visual studio 2010 at the moment

Upvotes: 2

Views: 2054

Answers (3)

niao
niao

Reputation: 5070

I resolved the problem. In my response object of type WCFREsponseGetAllProducts I had the following property

[DataMember]
public IQueryable<Product> Products {get;private set;}

The problem was that IQueryable is not serializable . I've changed it to Collection and now it works.

Upvotes: 0

Fredrik M&#246;rk
Fredrik M&#246;rk

Reputation: 158379

I see that you have resolved your issue, but I can still offer the advice to take a look at using the Service Trace Viewer to figure out what goes wrong in situations like these.

Upvotes: 3

Rob
Rob

Reputation: 45789

How big is the WCFResponseGetAllProducts being returned? I've encountered an issue previously due to the quantity of data that a method was returning.

Try adjusting the web.config file for your service by looking for the attributes maxArrayLength, maxBytesPerRead, maxDepth, maxNameTableCharCount and maxStringContentLength and increasing them.

You'll also need to do the same for the attributes in the configuration > system.serviceModel > bindings > wsHttpBinding section of the web.config file for your asp.net application, as well as (possibly) the maxBufferPoolSize and maxReceivedMessageSize values.

Upvotes: 0

Related Questions