1

我在WCF服务中定义了一个方法,它接受byte[]作为参数。当我调用函数时,它 An exception of type 'System.OutOfMemoryException' occurred in System.ServiceModel.ni.dll but was not handled in user codeReference.cs中给出了一个错误。

这是我的代码

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

其中内容是 byte[] 的对象。我有以下Web.config文件。

<?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" />

我已在IIS本地托管此服务。 内容对象包含17346288字节。我认为这个问题是由于互联网连接而出现的,但我的互联网连接工作正常。我得到了应该是什么错误?

4

2 回答 2

1

我有一个类似的问题。如果我记得,你必须在你的 WCF 服务中修改 app.xaml 文件并提供更多的 maxbytes、maxpool ......类似的东西

我误以为我更新了 Web.Config 文件并最大化了以下内容:

maxBufferSize、maxBufferPoolSize 等。

看这里:Large Binary (byte[]) File transfer through WCF

于 2013-08-02T10:13:00.037 回答
1

您的数据传输模式设置为缓冲区,它试图缓冲内存中的全部内容。检查这篇文章 - WCF HttpTransport:流式传输与缓冲传输模式

于 2013-08-01T14:10:10.853 回答