【发布时间】:2016-01-29 16:00:24
【问题描述】:
我有一个 WCF SOAP 服务,我正在尝试向该服务提交一个太大 (128KB) 的文件。我在网上搜索了很多关于添加 maxReceivedMessageSize、maxBufferSize 和其他此类属性的建议,但无济于事。我还将 maxRequestLength 添加到 httpRuntime ,但这也不起作用。不管我做什么,我都会得到 HTTP 错误 413:请求实体太大。
错误
HTTP Error 413: Request Entity Too Large.
网页配置
<httpRuntime targetFramework="4.5.1" maxRequestLength="1048576"/>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SomeBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" openTimeout="00:20:00"
receiveTimeout="00:20:00" closeTimeout="00:20:00" sendTimeout="00:20:00">
<readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
【问题讨论】:
-
WCF/SOAP 不是 HTTP 或 FTP。它们不是用来传输文件的。与其寻找增加允许文件大小的方法,不如考虑用允许 POST 文件的 HTTP 端点替换此服务。
-
抱歉,我的意思是,我正在读取文件的内容,然后在服务中将其作为字符串发送到方法中。文件的读取超出范围并且工作正常。
-
我明白你的要求。我是说将大文件作为 Web 服务参数发送是错误的。 如何发送它并不重要,尽管将它作为字符串参数发送比作为stream 发送它“错误”
标签: wcf .net-4.5.2