.NET Framework Bookmark and Share   
 index > Windows Communication Foundation > error when sending larga data in wcf
 

error when sending larga data in wcf

I have a function that returns a list more than 200000 objects and the object has 37 fields. I added the wcf as a web reference so i dont have to add any configuration item in my webapps config file. WCF works when I only have small amount of data. SInce I did'nt add the config file, how can I allow the wcf to send large amount of data. It sems to be timing out. When I debugged my wcf I'm getting this error "An error occurred while receiving the HTTP response to http://localhost:8731/Design_Time_Addresses/WCFService/Service1/. 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.
".
I understand that I'm passing large amount of data but that couldn't be the max amount of data that can be sent using wcf. I've been looking aroun and most of the solutions that I saw was to change the

<

binding name="NewBinding0" openTimeout="00:10:00" sendTimeout="00:30:00"

maxBufferSize="204003200" maxReceivedMessageSize="204003200">

on the client application but since I just added the wcf as a web reference I'm not using that.

Can anyone help me, I've been working on this for a while now and I'm stuck. Thanks in advance.

JaysonC
you will have to change the message size on the client side manually.
When you add the service reference, the feature adds WCF specific config entries for you. You will have to tweak the settings based on your needs.

HTH
Amit Sharma
Amit Sharma R
My client is a web app.Are you talking about my web.config file? The only line that was added in my web.config file when I added the web reference is this "<add key="WebService.Service" value="http://lpv-emmadv01.co.ihc.com:8080/Service.svc/Service"/>"

Is that where I have to change it? What do I add in the web config?
JaysonC
oh, I misread "web reference".
The settings appear when you add a Service Reference instead. But you wont have that option in .net 2.0

if your service is timing out, can you try to increase the apsnet timeout on the service side?

Amit Sharma
Amit Sharma R
I tried adding it as a service reference and change the values on the config file to this

<

binding name="basicHttpBinding" closeTimeout="00:10:00"

openTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:10:00"

allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"

messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

useDefaultWebProxy="true">

<

readerQuotas maxDepth="64" maxStringContentLength="819200" maxArrayLength="1638400"

maxBytesPerRead="409600" maxNameTableCharCount="1638400" />

Still I'm getting this error.
An error occurred while receiving the HTTP response to http://lpv-emmadv01.co.ihc.com:8080/EMMAService.svc/EMMAService. 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.

Do I need to make the values bigger? Do I need to change something on my wcf app.config?
JaysonC

Is the error on the server side? can you please enable tracing (http://msdn.microsoft.com/en-us/library/ms733025.aspx) on server side and see what is causing it to throw.
If you are hosting the service in IIS then I am guessing that you may have to configure httpruntime to allow large data.

<system.web>
<httpRuntime maxRequestLength="XXXX" />
</system.Web>


Amit Sharma
Amit Sharma R
Yes the service is hosted in IIS. Where do I put
<system.web>
<httpRuntime maxRequestLength="XXXX" />
</system.Web> ?
Does that go in the client application web.config or at the wcf app.config?

Thanks a lot.
JaysonC

can you try adding it to the side that is sending the large data


Amit Sharma
Amit Sharma R
An error occurred while receiving the HTTP response to http://xxxx.co.xxx.com:8080/xxxxService.svc/xxxxService. 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.

I added it int the wcf app.config and still giving me the error. Did i add that at the right place? Or should it be in the web.config? I dont have anything in the web.config, i added the bindings in the app.config. Since it's hosted in IIS should i be configuring the web.config?

Thanks.
JaysonC
web.config if it is the IIS app.
please enable tracing to get more information.
Amit Sharma
Amit Sharma R

This is the error from the trace:
</StackTrace><ExceptionString>System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/:Get_EquipmentsResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details. ---&amp;gt; System.Runtime.Serialization.SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.

at System.Runtime.Serialization.XmlObjectSerializerContext.IncrementItemCount(Int32 count)

wcf web.config file:
<basicHttpBinding>

<

binding name="basicHttpBinding" openTimeout="00:10:00" sendTimeout="00:10:00"

maxBufferSize="204003200" maxReceivedMessageSize="204003200"

transferMode="Buffered">

<

readerQuotas maxDepth="524288" maxStringContentLength="204003200"

maxArrayLength="524288" maxBytesPerRead="204003200" maxNameTableCharCount="524288" />

</

binding>

</

basicHttpBinding>



web application web.config

<

binding name="basicHttpBinding" closeTimeout="00:10:00"

openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"

allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

maxBufferSize="655360000" maxBufferPoolSize="52428800000" maxReceivedMessageSize="655360000"

messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

useDefaultWebProxy="true">

<

readerQuotas maxDepth="3200000" maxStringContentLength="819200000" maxArrayLength="1638400000"

maxBytesPerRead="409600000" maxNameTableCharCount="1638400000" />

<

security mode="None">

<

transport clientCredentialType="None" proxyCredentialType="None"

realm="" />

<

message clientCredentialType="UserName" algorithmSuite="Default" />

</

security>

</

binding>


Why is it still giving me that error when I already changed the '65536' to '655360000' in the wea application config and I have maxReceivedMessageSize="204003200" in my wcf config?

JaysonC
You need to add behaviorsin service and client configuration files.
On the service:

<behaviors>
<serviceBehaviors>
<behavior name="xxxxxxxxxxxxxxx">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="65536000" />
</behavior>
</serviceBehaviors>
</behaviors>

On the Client:
<behaviors>
<endpointBehaviors>
<behavior name="xxxxxxxxx">
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
</endpointBehaviors>
</behaviors>


Following threaddicusses this solution:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c85f3ed2-0b55-4375-af79-5926b6cc527c


Also,
http://blog.hill-it.be/post/2007/08/22/MaxItemsInObjectGraph-and-keeping-references-when-serializing-in-WCF

Thanks,
Pragna
Pragna Gopa
You need to add behaviorsin service and client configuration files.
On the service:

<behaviors>
<serviceBehaviors>
<behavior name="xxxxxxxxxxxxxxx">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="65536000" />
</behavior>
</serviceBehaviors>
</behaviors>

On the Client:
<behaviors>
<endpointBehaviors>
<behavior name="xxxxxxxxx">
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
</endpointBehaviors>
</behaviors>


Following threaddicusses this solution:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c85f3ed2-0b55-4375-af79-5926b6cc527c


Also,
http://blog.hill-it.be/post/2007/08/22/MaxItemsInObjectGraph-and-keeping-references-when-serializing-in-WCF

Thanks,
Pragna
Pragna Gopa
Thanks I think that fixed the error but now I'm getting different error.

Failed to allocate a managed memory buffer of 536870912 bytes. The amount of available memory may be low.

I've been searching about the error and most I've got is to change the transfer mode to streamed. My concern about that is there are other methods on the wcf and most of them only sends small amount ofdata. Actuallythe function the I'm using and causing the error normally does not send a lot of data. This is only the worst case scenario.

Is there a way to solve this error without having to use stream as transfer mode?

Thanks.
JaysonC
Streaming mode should beused forpassing large amouts of data

Also, following thread has more detials:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f00037f1-02e1-4e1c-b6ed-03fe134f3460

Thanks,
Pragna
Pragna Gopa

I'm still getting the error:

</StackTrace><ExceptionString>System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/:Get_EquipmentsResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details. ---&amp;gt; System.Runtime.Serialization.SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.

After I added this to wcf web.config:
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
</serviceBehaviors>
</behaviors>

and to client
<behaviors>
<endpointBehaviors>
<behavior name="WcfServiceLibrary.Service1Behavior">
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
</endpointBehaviors>
</behaviors>

And when I looked at the trace, I'm getting this error.
There was no channel actively listening at 'http://XXXX.co.XXX.com:8080/XXXXService.svc?wsdl'. This is often caused by an incorrect address URI.

JaysonC
Did u already tried this ?

<binding name="ABC" exactlyOnce="false" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"
maxStringContentLength="2147483647" />

Let me know how that goes....
WizBiz

You can use google to search for other answers

Custom Search

More Threads

• wcf service: objects lose property values when sent to client
• Where to start with VB?
• Could not connect to WCF service host in another computer
• Custom IPrincipal
• Sessions without certificates
• How to fill a collection with results from WCF Service
• Two IErrorHandler chained up, HandleError called too late
• New to WCF, questions about how to design a new service
• File stream problem
• WCF - generating proxy