0

我正在尝试使用回调同时向多个客户端发送大小超过 25 MB 的数据。我已经使用 wsdualhttp 绑定实现了该服务。当服务尝试同时将数据发送到 3 个以上的客户端时,它会引发“System.OutofMemory”和“无法分配内存”异常。我已经为 serviceThrottling、maxItemsInObjectGraph 以及 maxBufferPoolSize 设置了相关值。另外,我不能使用流媒体。有没有办法做到这一点?

// 服务器端

<?xml version="1.0"?>
<configuration>
<system.net>
<connectionManagement>
  <add address="*" maxconnection="2147483647"/>
</connectionManagement>
</system.net>  
<system.serviceModel>     
  <bindings>
   <wsDualHttpBinding>
     <binding name="WSConfig" closeTimeout="00:10:00" openTimeout="00:01:00" 
              receiveTimeout="00:20:00" sendTimeout="00:20:00" bypassProxyOnLocal="false" 
              transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" 
              maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" >
       <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
       <reliableSession ordered="true" inactivityTimeout="00:10:00"/>
     </binding>
   </wsDualHttpBinding>
 </bindings>     
 <services>
   <service behaviorConfiguration="ServiceBehavior"     name="CallbackService.MycallbackService">
     <endpoint address="http://localhost:8000/MycallbackService/MyService" binding="wsDualHttpBinding" contract="CallbackService.IServiceContract" bindingConfiguration="WSConfig">
         <identity>
         <dns value="localhost"/>
       </identity>           
     </endpoint>                 
   </service>       
 </services>
 <behaviors>
   <serviceBehaviors>
     <behavior name="ServiceBehavior">
       <serviceMetadata httpGetEnabled="true"/>
       <serviceDebug includeExceptionDetailInFaults="false "/>
      <serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="1000"/>
       <dataContractSerializer maxItemsInObjectGraph="2147483646"/>           
     </behavior>
   </serviceBehaviors>
 </behaviors>      
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>    
</configuration>

//客户端

<?xml version="1.0"?>
<configuration>
<system.net>
<connectionManagement>
  <add address ="*" maxconnection = "2147483647" />
</connectionManagement>
</system.net>
<system.serviceModel>
<bindings>
  <wsDualHttpBinding>
    <binding name ="WSConfig" closeTimeout="00:10:00"
   openTimeout="00:01:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
   bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
   maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
   messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"/>
    </binding>
  </wsDualHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:8000/MycallbackService/MyService" binding="wsDualHttpBinding" contract="CallbackService.IServiceContract" bindingConfiguration ="WSConfig">     
  </endpoint>
</client>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>    

4

1 回答 1

0

对于那些仍在调查的人:我遇到了同样的问题,结果发现交换的数据对于序列化器/反序列化器来说太大了。这反过来又导致 System.OutofMemory 错误。您可能想尝试其他一些绑定(例如支持二进制编码的 NetTcpBinding)

另外:确保您的客户端和服务都针对相同的体系结构进行编译(如果您的服务地址为 64 位命名空间并且您的客户端针对 32 位进行编译,那么您一定会遇到 System.OutofMemory 异常

于 2014-06-05T08:03:02.570 回答