Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

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

I am trying to save a huge data to database through a WCF service call. I am not able to invoke the service. Its throwing a error.

codeProxy.SaveCodes(requestHeader, codes, Rawcodes);

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

I have configued the web config on server and client side to max limits.

client web.config

<binding name="WSHttpBinding_dataService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                    <security mode="None">
                        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
                    </security>
                </binding>

server web.config

<service name="ser.WSHttpBinding_dataService" behaviorConfiguration="ServiceBehavior">
      <endpoint contract="ser.IDataservice" binding="wsHttpBinding" bindingConfiguration="datacodeservice" />
      </service>

<wsHttpBinding>
        <binding name="datacodeservice" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
          <security mode ="None">
            <!--<message clientCredentialType="Certificate" />-->
          </security>
        </binding>


<serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceThrottling maxConcurrentSessions="100" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>

        </behavior>
      </serviceBehaviors>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use Stream property in message contract of WCF operation to transfer large objects.

[MessageContract]
public class DocumentDescription
{
    [MessageBodyMember(Namespace = "http://example.com/App")]
    public Stream Stream { get; set; }
}

Configure your binding this way

<binding name="Binding_DocumentService" receiveTimeout="03:00:00"
        sendTimeout="02:00:00" transferMode="Streamed" maxReceivedMessageSize="2000000">
    <security mode="Transport" />
</binding>

To upload large data into SQL Server database use approach described in the following article Download and Upload images from SQL Server via ASP.Net MVC


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...