SilverLight調(diào)用WCF,提交的是一個(gè)List<Linq2SqlEntity>;當(dāng)List中數(shù)據(jù)量不大的時(shí)候,不會(huì)報(bào)錯(cuò);當(dāng)數(shù)據(jù)量稍微大一點(diǎn)兒,就會(huì)出現(xiàn)這個(gè)錯(cuò)誤。發(fā)生了 System.ServiceModel.ProtocolException
Message=已超過傳入消息(65536)的最大消息大小配額。若要增加配額,請(qǐng)使用相應(yīng)綁定元素上的 MaxReceivedMessageSize 屬性。
Source=System.ServiceModel
StackTrace:
在 System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
費(fèi)了牛勁在網(wǎng)上搜了一通,有的說是要修改behavior的maxItemsInObjectGraph,有的說要修改binding的maxBufferSize/maxReceivedMessageSize,有的說要增加readerQuotas,有的是endpoint沒有與自定義binding配置節(jié)關(guān)聯(lián)起來,有的說要客戶端和服務(wù)器端都要改(我的應(yīng)用中,接受數(shù)據(jù)的是服務(wù)器端,客戶端負(fù)責(zé)提交,所以應(yīng)該不關(guān)客戶端的事兒)。。。然后把server端的配置文件調(diào)整成下面這樣:
1: <system.serviceModel> 2: <behaviors> 3: <serviceBehaviors>4: <behavior name="MessageHeaderOperationBehaviourAuthenticationBehavior">
5: <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
6: <serviceMetadata httpGetEnabled="true"/>
7: <serviceDebug includeExceptionDetailInFaults="true"/>
8: </behavior> 9: </serviceBehaviors> 10: </behaviors>11: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
12: <services>13: <service behaviorConfiguration="MessageHeaderOperationBehaviourAuthenticationBehavior"
14: name="MessageHeaderOperationBehaviourAuthentication">
15: <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeSize" contract="DyeService">
16: </endpoint> 17: </service> 18: </services> 19: <bindings> 20: <basicHttpBinding>21: <binding name="LargeSize" maxBufferSize="2147483647"
22: maxBufferPoolSize="21474836471" maxReceivedMessageSize="2147483647">
23: <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
24: maxArrayLength="2147483647" maxBytesPerRead="2147483647"
25: maxNameTableCharCount="2147483647" />
26: <security mode="None" />
27: </binding> 28: </basicHttpBinding> 29: </bindings> 30: </system.serviceModel>但是問題依舊。最后在stackoverflow找到了正解:WCF Error - unexpected response: (400) Bad Request.,里面鏈接到了另一篇帖子:Cannot get the MaxReceivedMessageSize higher than (65536)
解決辦法就是:配置文件中,service 的name屬性必須與服務(wù)的類型全名稱保持一致,才能應(yīng)用上自定義的配置節(jié)。
按著這個(gè)方法,調(diào)整之后的配置文件如下所示(刪掉了其他無關(guān)的maxItemsInObjectGraph、readerQuotas等):
1: 2: <system.serviceModel> 3: <behaviors> 4: <serviceBehaviors>5: <behavior name="MessageHeaderOperationBehaviourAuthenticationBehavior">
6: <serviceMetadata httpGetEnabled="true"/>
7: <serviceDebug includeExceptionDetailInFaults="true"/>
8: </behavior> 9: </serviceBehaviors> 10: </behaviors>11: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
12: <services>13: <service behaviorConfiguration="MessageHeaderOperationBehaviourAuthenticationBehavior"
14: name="NameSpace.DyeService">
15: <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeSize" contract="NameSpace.DyeService">
16: </endpoint> 17: </service> 18: </services> 19: <bindings> 20: <basicHttpBinding>21: <binding name="LargeSize" maxBufferSize="2147483647"
22: maxBufferPoolSize="21474836471" maxReceivedMessageSize="2147483647">
23: </binding> 24: </basicHttpBinding> 25: </bindings> 26: </system.serviceModel>
浙公網(wǎng)安備 33010602011771號(hào)