WCF服务中的大文件
我有一个WCFSOAP服务,我试图向该服务提交一个太大(128KB)的文件。我浏览了互联网,找到了许多关于添加maxReceivedMessageSize、maxBufferSize和其他类似属性的建议,但都没有用。我还向httpRuntime添加了maxRequestLength,但这也不起作用。不管我做什么我都会得到 HTTP错误413:请求实体太大 错误 网络配置WCF服务中的大文件,wcf,.net-4.5.2,Wcf,.net 4.5.2,我有一个WCFSOAP服务,我试图向该服务提交一个太大(128KB)的文件。我浏览了互联网,找到了许多关于添加maxReceivedMessageSize、maxBufferSize和其他类似属性的建议,但都没有用。我还向httpRuntime添加了maxRequestLength,但这也不起作用。不管我做什么我都会得到 HTTP错误413:请求实体太大 错误 网络配置 <httpRuntime targetFramework="4.5.1" maxRequestLength="10485
<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>
即使您在绑定中设置了更大的配额,该绑定也不会被您的服务使用,因为它从未分配给端点或设置为
基本绑定的默认绑定
由于您的配置文件中没有定义明确的端点,因此可以通过省略name
属性将绑定配置设置为basicHttpBinding
的默认值,如下所示:
<binding 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
的所有请求的默认值(或将其分配给显式端点),服务将使用默认值(或更小值)创建绑定
有关默认绑定(以及端点和行为)的更多信息,请参阅。@Tim我在网上的几个地方看到了这一点,它是正确的,只是缺少了一些其他内容。我很困惑,因为我是WCF的新手,我的服务包装了另一个服务,这样我就可以在不改变现有系统的情况下执行新的逻辑。因此,我所做的任何更改只适用于我呼叫的客户。您需要将以下
添加到
中,以便将这些更改应用于服务
<services>
<service name="ANX.DEX001.WebService.EtPrintService">
<endpoint name="basicHttpBinding"
address="/EtPrintService.svc"
binding="basicHttpBinding"
contract="ANX.DEX001.WebService.IEtPrintService"
bindingConfiguration="APIPortBinding"/>
</service>
</services>
WCF/SOAP不是HTTP或FTP。它们不是用来传输文件的。不要寻找增加允许文件大小的方法,你应该考虑用一个允许发布文件的HTTP端点来替换这个服务。抱歉,我想说的是,我正在读取一个文件的内容,然后用一个方法将它发送到服务中的一个字符串中。文件读取超出范围,工作正常。我理解您的要求。我是说,将大文件作为web服务参数发送是错误的。如何发送并不重要,尽管作为字符串参数发送比作为字符串参数发送“错误”
<services>
<service name="ANX.DEX001.WebService.EtPrintService">
<endpoint name="basicHttpBinding"
address="/EtPrintService.svc"
binding="basicHttpBinding"
contract="ANX.DEX001.WebService.IEtPrintService"
bindingConfiguration="APIPortBinding"/>
</service>
</services>