简体   繁体   English

WCF-增加REST服务上的ReaderQuoatas

[英]WCF - Increase ReaderQuoatas on REST service

I have a WCF REST Service which accepts a JSON string 我有一个WCF REST服务,它接受JSON字符串

One of the parameters is a large string of numbers 参数之一是一大串数字

This causes the following error - which is visible by tracing and using SVC Trace Viewer 这将导致以下错误-通过跟踪和使用SVC跟踪查看器可以看到

There was an error deserializing the object of type CarConfiguration. 反序列化CarConfiguration类型的对象时发生错误。 The maximum string content length quota (8192) has been exceeded while reading XML data. 读取XML数据时,已超出最大字符串内容长度配额(8192)。 This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. 通过更改在创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxStringContentLength属性,可以增加此配额。

Now I've read all sorts of articles advising how to rectify this 现在,我阅读了各种文章,建议如何纠正此问题

All of them recommend increasing various config settings on the server and client 他们所有人都建议增加服务器和客户端上的各种配置设置

eg Error Serializing String in WebService call 例如, 在WebService调用中错误序列化字符串

http://bloggingabout.net/blogs/ramon/archive/2008/08/20/wcf-and-large-messages.aspx http://bloggingabout.net/blogs/ramon/archive/2008/08/20/wcf-and-large-messages.aspx

http://social.msdn.microsoft.com/Forums/en/wcf/thread/f570823a-8581-45ba-8b0b-ab0c7d7fcae1 http://social.msdn.microsoft.com/Forums/en/wcf/thread/f570823a-8581-45ba-8b0b-ab0c7d7fcae1

So my config file looks like this 所以我的配置文件看起来像这样

 <webHttpBinding>
        <binding name="webBinding" maxBufferSize="5242880"  maxReceivedMessageSize="5242880" >
          <readerQuotas  maxDepth="5242880" maxStringContentLength="5242880" maxArrayLength="5242880" maxBytesPerRead="5242880" maxNameTableCharCount="5242880"/>
        </binding>
   </webHttpBinding>
...
...
...
<endpoint 
      address="/"
      binding="webHttpBinding"
      bindingConfiguration="webBinding"

My problem is that I can change this on the server, but there are no WCF config settings on the client as its a REST service and I'm just making a http request using the WebClient object 我的问题是我可以在服务器上更改此设置,但是客户端上没有WCF配置设置作为其REST服务,而我只是使用WebClient对象发出http请求

any ideas? 有任何想法吗?

so it turns out you need a fullly qualified url on the endpoint address, not a relative one 所以事实证明您需要在端点地址上使用完全限定的url,而不是相对的

Error calling a WCF REST service using JSON. 使用JSON调用WCF REST服务时出错。 length quota (8192) exceeded 超出长度配额(8192)

That error wouldn't be happening on the client, since reader quotas are a WCF-only thing and WebClient/HttpWebRequest don't do deserialization themselves or enforce any other kind of quotas. 该错误不会在客户端上发生,因为读者配额仅是WCF,并且WebClient / HttpWebRequest本身不会反序列化或强制执行任何其他种类的配额。

So I'd say say that it's likely you're putting the configuration in the wrong place and it's not getting picked up. 因此,我想说的是,您可能会将配置放在错误的位置,并且没有被使用。

Either that or... you're not using one of the WCF DataContract Serializers manually on the client side, are you? 要么,要么...您没有在客户端手动使用WCF DataContract序列化程序之一,对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM