WCF配置文件分为服务端配置文件及客户端配置文件,很多配置项都是需要前后台同时支持的,具体的信息可以参见:WCF配置文件注释 及 WCF配置文件全攻略
1.maxStringContentLength="2097152"
在客户端配置 maxStringContentLength
2. The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
此异常信息非常明确的指出应当修改客户端配置文件中的 MaxReceivedMessageSize属性,可参考如下代码片段:
需要注意的是,好像需要同时修改maxBufferSize属性的值与MaxReceivedMessageSize属性值相同,否则还会报出另外的异常。
3. The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader.
此异常信息指示应当修改 MaxDepth属性的值,但修改客户端配置是没有用的,应当参考如下代码修改服务器端配置:
4. There was an error while trying to serialize parameter http://tempuri.org/:GetSuppliersResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details.
http://localhost/cdms3.Service/BasicData/BasicDataService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
为了获取更详细的错误信息,只得祭起svcTraceViewer大旗,关于svcTraceViewer及svcConfigEditor工具的使用可参见:使用svcTraceViewer来调试WCF异常
于是便找到了如上面标题所述的异常信息,由此可知应当修改MaxItemsInObjectGraph属性值,在上述引用的文章中其实已经给出了解决方案,只是未给出实例代码,像我这种初学者还是花了点时间来配置MaxItemsInObjectGraph属性,应当同时修改前后台配置文件。
1)修改服务器端配置文件,在当前使用的Behavior节点中增加<dataContractSerializer maxItemsInObjectGraph="6553600" />,示例代码片段如下:
2)然后修改客户端配置文件,增加maxItemsInObjectGraph配置
如果在上述配置节点中为Behavior节点设置了名称,如:<behavior name="MyBehavior">,那么还应当修改endpoint节点,设定其使用的Behavior配置:behaviorConfiguration="MyBehavior",凡是未特别指定behaviorConfiguration的endpoint将使用默认的Behavior配置(即无name属性的behavior)。