Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can any one please help me its urgent.

I am having one lakh record in my datatable while compress and de compress and after serialize i am getting Exception of type 'System.OutOfMemoryException' was throw

I AM USING WCF+WPF

My Code is

C#
public static MemoryStream DataTableSerialization(DataTable dtSearchDataTable)
{
    System.IO.MemoryStreamstream = newSystem.IO.MemoryStream();
 
    System.Runtime.Serialization.IFormatterformatter = newSystem.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    byte[] bytes = null;

    MemoryStream memory = new MemoryStream();  

    try
    {
        dtSearchDataTable.RemotingFormat = SerializationFormat.Binary;
        
        formatter.Serialize(stream, dtSearchDataTable);//Here i am getting error 
        bytes = stream.ToArray();
        
        using (vargzip = newGZipStream(memory, CompressionMode.Compress, true))
        {
            gzip.Write(bytes, 0, bytes.Length);
        }
        
        memory.Position = 0; 
        
        // ---  In order to enable reading option during Deserialzation on client side we need to set Position = 0
        }
    catch(Exceptionex)
    {  
    } 
    finally
    
    {
        stream.Dispose();
        MinimizeMemory();
    }            

    return memory;
}


My Webconfig(WCF)

HTML
<opentimeout receivetimeout="04:10:00" sendtimeout="04:01:00">
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"           
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"    
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true"      
allowCookies="false">
<readerQuotasmaxdepth maxstringcontentlength="2147483647" maxarraylength="2147483647">
 
maxBytesPerRead="4096"maxNameTableCharCount="16384"/>
                 bindingname="SearchBinding"closeTimeout="04:01:00">
</readerquotasmaxdepth>
</opentimeout>



- Edit MK -
Added code tags. Didn't even try to correctly format the web.config part though, it's an incomplete snippet. Please sort that out.
Posted
Updated 10-Apr-14 1:45am
v2
Comments
[no name] 10-Apr-14 7:44am    
I take it that "one lakh" is a lot? Perhaps that is more than WCF can serialize at one time.
Bernhard Hiller 11-Apr-14 4:34am    
Update your question - "System.IO.MemoryStreamstream = newSystem.IO.MemoryStream();" won't compile.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900