2009-01-11 51 views
0

我有一个数据服务需要一个字节数组。然后我有一个网页,试图发送文件到该数据服务。如果文件很小(比如说50kb),那么一切都按预期运行,但是如果文件很大(超过100kb),我会在数据服务的保存更改调用中收到“BadRequest”错误消息。如何增加发送到ADO.Net数据服务的数据大小?

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

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

+0

你在哪里更改MaxReceivedMessageSize? – cmsjr 2009-01-12 01:03:24

回答

5

其中WCF服务可以处理通过在WCF结合MaxReceivedMessageSize属性控制所述请求的最大大小。 默认值是65536,超过此值可以获得400响应代码。

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

<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属性。

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

确定WCF是否抛出了一个异常,而这些异常是在HTTP级别上未呈现给您的。您可以configure WCF tracing on the server-side从WCF层记录必要的信息。一旦跟踪设置并重现失败,请检查日志是否包含这些异常消息中的一个或两个。

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." 

如果您看到日志包含此消息,那么可以肯定的是,失败是因为消息的大小和应用此相应的修正。

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

3

我也试着编辑没有结果的web.config文件。我仍然得到同样的例外。

一个适用于我的解决方案是编辑machine.config文件,并在System.ServiceModel节点中添加以下行。

<standardEndpoints> 
     <webHttpEndpoint> 
      <standardEndpoint name="" maxReceivedMessageSize="16777216" maxBufferSize="16777216" /> 
     </webHttpEndpoint> 
    </standardEndpoints> 

我不知道这是否是正确的解决方案,但它适用于我。