如何增加发送到 ADO.Net 数据服务的数据大小? [英] How do I increase the size of data sent to ADO.Net Data Services?

查看:19
本文介绍了如何增加发送到 ADO.Net 数据服务的数据大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个采用字节数组的数据服务.然后我有一个网页,尝试将文件发送到该数据服务.如果文件很小(比如 50kb),那么一切都按预期运行,但是如果文件很大(超过 100kb),我会在数据服务的保存更改调用中收到BadRequest"错误消息.

I have a data service that takes a byte array. I then have a web page that attempts to send a file to that data service. If the file is small (say 50kb) then everything functions as expected, however if the file is large (anything over 100kb) I get a "BadRequest" error message on the save change call for the data service.

有没有办法将更大的数据传递给数据服务?

Is there a way to enable larger data sizes to be passed to the data service?

编辑(更多细节):我已经将 maxRequestLength 设置得更高,并尝试了一些 webHttpBinding 来增加 maxReceivedMessageSize,但这些似乎没有帮助.

EDIT (more details): I've set maxRequestLength higher and tried some webHttpBinding to increase maxReceivedMessageSize, but these do not seem to be helping.

推荐答案

WCF 服务可以处理的请求的最大大小由 WCF 绑定上的 MaxReceivedMessageSize 属性控制.默认值是 65536 ,超过它你会得到 400 响应代码.

The maximum size of the request which a WCF service can process is controlled by the MaxReceivedMessageSize property on the WCF binding. The default value is 65536 ,exceeding which you get the 400 response code.

在托管服务的网站的 web.config 中,在该部分添加以下节点.

In the web.config of the web site hosting the service , add the following node in the section.

<system.serviceModel> 
<services> 
  <!-- The name of the service --> 
  <service name="NorthwindService"> 
    <!-- you can leave the address blank or specify your end point URI --> 
    <endpoint address ="YourServiceEndpoint" 
              binding="webHttpBinding" bindingConfiguration="higherMessageSize" 
     contract ="System.Data.Services.IRequestHandler"> 
    </endpoint> 
  </service> 
</services> 
<bindings> 
  <webHttpBinding> 
    <!-- configure the maxReceivedMessageSize  value to suit the max size of 
         the request ( in bytes ) you want the service to recieve--> 
    <binding name="higherMessageSize" maxReceivedMessageSize ="MaxMessageSize"/> 
  </webHttpBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
</system.serviceModel>

如果托管在 IIS 上,ASP.Net 请求大小限制也会导致大型请求被拒绝,您需要设置 HttpRuntimeSection.MaxRequestLength 属性.

If hosted on IIS , the ASP.Net Request Size restriction can also cause a large request to be rejected, You will need to set the HttpRuntimeSection.MaxRequestLength Property.

<system.web> 
  <httpRuntime MaxRequestLength="ValueInKiloBytes" />
</system.web>

确定 WCF 是否在掩护下抛出异常,而该异常并未在 HTTP 级别显示给您.您可以在服务器端配置 WCF 跟踪以记录必要的信息从 WCF 层.完成跟踪设置并重现失败后,请检查日志是否包含这些异常消息之一或两者.

Identify if WCF is throwing an exception under the covers which is not being surfaced to you at the HTTP level. You can configure WCF tracing on the server-side to log the necessary information from the WCF layer. Once you have tracing setup and you reproduced the failure , check if the log contains one or both of these exception messages.

System.ServiceModel.ProtocolException
"The maximum message size quota for incoming messages (65536) has been exceeded. 
To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."

System.Web.HttpException
"Maximum request length exceeded."

如果您看到日志确实包含此消息,那么您可以确定失败是由于消息大小并相应地应用此修复程序.

If you see that the log does contain this message , then you can be sure that the failure is because of the message size and apply this fix accordingly.

PD:请记住,您的表单必须使用 "POST" 方法.

PD: Remember that your form must use the "POST" method.

这篇关于如何增加发送到 ADO.Net 数据服务的数据大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆