我有一個令人迷惑的問題,我無法找到答案。我正在嘗試將大量數據上傳到WCF服務,並且在第一次和後續嘗試中將返回413錯誤,直到接受大數據請求之後發送64kb限制下的請求爲止。 我已經在我的綁定中擴展了maxReceivedMessageSize和maxStringContentLength元素,並且這解決了在初始小請求之後發送請求時(如果這些請求沒有被擴展一個不同的錯誤400返回不是413)的問題。WCF服務在第一次加載時以413響應
我的系統是在IIS 7上運行的ASP.NET 3.5應用程序,WCF服務使用自定義綁定,SOAP消息和客戶端/服務器證書。
基本上爲了再現如下(2個服務器測試)
- IIS7工作進程啓動
- 發送請求大於64KB:返回413錯誤
- 發送任何更多的請求大於64kb:返回413錯誤
- 發送請求小於64kb:返回200和有效肥皂響應
- 發送請求大於64kb:返回200和有效肥皂響應
如果maxReceivedMessageSize和maxStringContentLength元素不增加發生以下情況:
- IIS7工作進程啓動
- 發送請求大於64KB:返回413錯誤
- 發送任何更多的請求大於64kb:返回413錯誤
- 發送請求少於64kb:返回200和有效肥皂響應
- 發送要求大於64KB:返回400錯誤
調試表明,收到413錯誤時,服務器還沒有真正初始化我的服務,一旦一個小請求到來時它被初始化,並注重結合我的規則,然後允許大量數據。
我懷疑這是WCF庫內部的一個問題,可能通過升級來解決,但這不是一個真正的選擇,需要解決。我正沿在應用程序啓動的思路思考問題初始化服務一些如何或可能增加默認WCF最大接收字節莫名其妙
從我的web.config:
<system.web>
<httpRuntime maxRequestLength="65536" executionTimeout="1800"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="67108864" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceTlsBehavior" name="ELSLookupServiceTLS">
<endpoint address="" binding="customBinding" bindingConfiguration="TlsBinding" contract="Lookup" />
</service>
</services>
<bindings>
<customBinding>
<binding name="TlsBinding" closeTimeout="00:04:00" openTimeout="00:12:00" receiveTimeout="00:15:00" sendTimeout="00:05:00">
<textMessageEncoding>
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
</textMessageEncoding>
<httpsTransport requireClientCertificate="true" maxReceivedMessageSize="6553600" maxBufferPoolSize="6553600" maxBufferSize="6553600" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceTlsBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我的服務實現:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class ELSLookupService : Lookup
{
//serivce call implemented here
}