1

I have define a method in WCF service, which accept byte[] as parameter. When I call function it gives my an error An exception of type 'System.OutOfMemoryException' occurred in System.ServiceModel.ni.dll but was not handled in user code in Reference.cs.

Here is my code

svc.GetDataUsingDataContractCompleted += new EventHandler<GetDataUsingDataContractCompletedEventArgs>(svc_GetDataUsingDataContractCompleted);
svc.GetDataUsingDataContractAsync(contents, "AllImagesZip.zip");

Where contents is object of byte[]. I have following Web.config file.

<?xml version="1.0"?>
<configuration>
<appSettings>
   <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" executionTimeout="300" maxRequestLength="409600"/>
</system.web>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <!--<binding maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:10:00" closeTimeout="00:10:00">
      <security mode="None" />
    </binding>-->
  <binding name="basicHttpsBinding" closeTimeout="01:01:00"
  openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00"
  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
  maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
  messageEncoding="Mtom" textEncoding="utf-8" transferMode="StreamedRequest"
  useDefaultWebProxy="true">
  <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
    maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
  <security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None"
      realm="" />        
  </security>
</binding>    
  </basicHttpBinding>    
</bindings>   

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding"  scheme="https"/>
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

I have hosted this service locally in IIS. Contents object contain 17346288 byte. I think that this issue comes because of internet connection, but I internet connection works fine. I am getting what should be the error?

Ajay
  • 6,418
  • 18
  • 79
  • 130

2 Answers2

1

Your data transfer mode is set to buffer which tries to buffer entire content in memory. check this post - WCF HttpTransport: streamed vs buffered TransferMode

Community
  • 1
  • 1
vibhu
  • 1,657
  • 2
  • 15
  • 19
1

I had a similar problem. If i remember, you have to modify app.xaml file in you'r WCF service and give more maxbytes, maxpool... something like that

I've mistaken i updated Web.Config file and maximized suh things as:

maxBufferSize, maxBufferPoolSize and others.

Look here: Large Binary (byte[]) File transfer through WCF

Community
  • 1
  • 1
Developer
  • 4,158
  • 5
  • 34
  • 66
  • What type of change I have to do in app.xaml ? – Ajay Aug 02 '13 at 10:18
  • I am getting this error "The remote server returned an unexpected response: (413) Request Entity Too Large. In Silverlight, a 404 response code may be reported even when the service sends a different error code." I have updated my code – Ajay Aug 02 '13 at 10:50
  • @ajaypunekar Silverlight has a 4mb limit for entities storage but a lot lower one for incoming entities from outside applications if you break down you char[] then send it and reassemble when it is received in bits you may have more joy (not how to do this as new to wcf) – ZoomVirus Oct 10 '14 at 08:40