Error calling a WCF REST service using JSON. length quota (8192) exceeded

有些话、适合烂在心里 提交于 2019-12-06 06:16:07

This works, just make sure to have a full absolute URL as your endpoint address. If you get crafty and try to use a relative path, or if you omit .svc it will bomb with the strange reader quota error once the request gets too large --

I would file this under a Bug for WCF because either:

  1. relative URLs should be disallowed (and an appropriate exception thrown)

or

  1. the reader quota should work with relative paths as well

Insert into your web.config:

<configuration>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingConfig">
          <readerQuotas maxStringContentLength="2048000" />
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

and insert attribute bindingConfiguration="webHttpBindingConfig" into your endpoint

I had similar problems but with .NET 3.5

I had no problems on the server log, so the problem was on the client. Seems that the configuration with the max values increased was not read and used...

So I solved passing the name of the endpoint EXPLICITLY in the constructor of the WebChannelFactory, using another overload.

WAS:

WebChannelFactory<IWKRestTest> factory = new WebChannelFactory<IWKRestTest>(new Uri(XXX));
factory.Credentials.UserName.UserName = K_USERNAME;
factory.Credentials.UserName.Password = K_PASSWORD;
IWKRestTest proxy = factory.CreateChannel();

IS:

WebChannelFactory<IWKRestTest> factory = new WebChannelFactory<IWKRestTest>("IWKRestTestService");

and in the app.config there's:

The Uri is indicated in the endpoint node but there you find also the bindingConfiguration and so on, so all the new increased limits now works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!