English 中文(简体)
在将大量数据发送到网络服务 c#
原标题: System.OutOfMemoryException while sending large amount of data to webservice c#

I get "Out of Memory Exception" while sending large data using web services. It works fine for small amount of data. Scenario is like : Here i have entity class called clsMovie. Here user uploads large file more than 250 MB.this file gets converted to bytes of array and assigned to MovieData member of clsMovie class. when object of this class is passed to web service with large amount of data(large bytes of array), I get "Out of Memory Exception".

代码是 :

MovieResponse objM = service.SaveProductMovie(objMovieEnt);     // I get "Out of Memory Exception".


    [DataContract]
    [Serializable]
    public class clsMovie
    {
        [DataMember]
        public byte[] MovieData { get; set; }

        [DataMember]
        public string MovieType { get; set; }

        [DataMember]
        public int MovieSize { get; set; }

    }

I tried to use WSE 3.0 Tool but it is not supported in VS 2008 and also i googled a lot,but all in vain. Anyone have solution?

问题回答

在网络服务上发送250 MB的阵列会消耗大量内存, 您可能需要 3 倍于 250 MB 的自由内存来处理阵列 。 如果您有 10 个用户上传, 那么会发生什么? 此外, 如果您做一个肥皂信息, 您的250 MB 文件的大小大约是 250 MB 的 10 倍, 也就是 xml, 每个字节都转换成字符 + xml 标记 。

有更好的协议, 然后 Webserices 发送大文件, 例如当 ftp 上传完成后, 您可以使用 ftp 将上传文件的名称发送到 Webserice 上传文件 。 或者做 5 MB chuck, 并合并最后一个 chuck 出现时 。

您可以检查您的配置文件, 在绑定中设定大小配额 。

<basicHttpBinding>
   <binding name="BasicHttpBinding_ForgotPasswordService" closeTimeout="00:10:00"
       openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
       allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
       maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
       useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
       maxBytesPerRead="4096" maxNameTableCharCount="16384" />
   </binding>
</basicHttpBinding>

您可以根据您的需要调整 maxBofferSize="65536" 最大缓冲poolSize="524288" 最大接收量MessageSize="65536"

但是,在“强”你的个案 中,我最好考虑一下周转基金的流能力,比如这里:“Large Data and Streaming in WCF ”(MSDN)

<强 > [EDIT]

想想看,如果你达到配额限制, 例外很可能是不同的, 并告诉你喜欢“最大数组长度配额已经超过”或类似的东西。

out of memoryExption 可能更多与至少一个通信系统的实际限值有关。 原因可能是将数据装入内存并不够清理( 或足够快) 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签