Tru*_*ill 26 iis wcf web-config .net-4.0 wcf-binding
我对WCF Web服务的调用失败了 System.Net.WebException: The request failed with HTTP status 413: Request Entity Too Large.
检查提琴手,我看到我正在发送:
内容长度:149839
超过65KB.
在服务器上启用WCF跟踪,我看到:
System.ServiceModel.ProtocolException:已超出传入邮件的最大邮件大小配额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性.
添加此属性不能解决问题.
我已经尝试过这个属性,并且(稍后)与帖子建议的各种其他人一起尝试过.这是我目前(在服务器上):
<basicHttpBinding>
<binding name="PricerServiceSoap"
closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
我唯一的终点(下<client>
)是:
<endpoint address="/NetPricingService/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="PricerServiceSoap"
contract="Pricing.PricerService.PricerServiceSoap"
name="PricerServiceSoap" />
Run Code Online (Sandbox Code Playgroud)
我还补充说:
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
Run Code Online (Sandbox Code Playgroud)
在<behavior>
.
我甚至跑(对于IIS 7):
%windir%\system32\inetsrv\appcmd set config "WebServicesDev/PricingService"
-section:requestFiltering -requestLimits.maxAllowedContentLength:104857600
-commitpath:apphost
Run Code Online (Sandbox Code Playgroud)
没有任何区别.
一个问题是,这是一个WCF服务,旨在取代旧的ASMX服务.服务框架是使用现有WSDL中的svcutil生成的.我无法更改客户端配置(客户端使用多种语言).我的测试客户端项目使用Add Web Reference(下Add Service Reference / Advanced
)导入了该服务,因此我没有WCF配置.但是,如果我将它指向较旧的ASMX服务,则测试客户端可以正常工作.
我该如何修复或诊断?
附加信息
如果我使用Microsoft服务配置编辑器生成配置(设置maxReceivedMessageSize和maxBufferSize),它可以工作.问题是然后指定端点<service>
,它不允许我指定/NetPricingService/Service.asmx相对地址.如果我在svcutil生成的配置中编辑绑定(端点所在的位置<client>
),则它不适用于大型请求.
Tru*_*ill 25
答案是盯着我的脸.
svcutil生成的配置是针对客户端的.我在服务器上使用它.
我正在编辑指定的端点的绑定<client>
,这对服务没有任何区别.
添加适当的<service>
端点并在其绑定上设置maxReceivedMessageSize和maxBufferSize解决了该问题.
mat*_*rns 24
我遇到了类似的问题.对我来说,问题是我的端点没有使用明确命名绑定bindingConfiguration
,因此必须在某处使用某个默认值.
我有:
<webHttpBinding>
<binding
name="myXmlHttpBinding"
maxReceivedMessageSize="10485760"
maxBufferSize="10485760">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</webHttpBinding>
Run Code Online (Sandbox Code Playgroud)
我的端点定义为:
<service
name="blah.SomeService">
<endpoint
address=""
behaviorConfiguration="WebHttpBehavior"
binding="webHttpBinding"
contract="blah.ISomeService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
Run Code Online (Sandbox Code Playgroud)
一旦我将端点更改为:
<service name="blah.SomeService">
<endpoint address=""
behaviorConfiguration="WebHttpBehavior"
binding="webHttpBinding"
bindingConfiguration="myXmlHttpBinding"
contract="blah.ISomeService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
Run Code Online (Sandbox Code Playgroud)
我也遇到了这个问题,并在 fiddler 中意识到正在工作的最大 Content-Length 最终是 30000000。
在验证我的 WCF 配置正确后,我发现一篇文章建议修改 IIS 设置请求过滤。
Web 应用程序调用 WCF 服务的大文件上传失败 – 413 请求实体太大
或 web.config 文件示例
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="50000000" />
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
59435 次 |
最近记录: |