开发者

WCF (Rest) service errors when JSON object has a long string

I have a WCF service implemented using the WebServiceHostFactory (REST).

I'm calling a service end point as a POST sending a json object that has a string property.

This works up to a point but it seems that if the length of that string gets too long (not sure exactly how long (8000 chars works but 9000 does not ... I did not try but 'breaking point' might be 8192).

I attempt to check the StatusCode in the call back which works fine for smaller strings but when the sting is 'too long' the code below errors with:

System.Net.WebException: The remote server returned an error: NotFound.

Callback code:

var request = (H开发者_如何学GottpWebRequest)result.AsyncState;
var response = (HttpWebResponse)request.EndGetResponse(result);

I'm trying to figure out where the problem is, since the service exists and I only get this when the string is too long.

Is it the json object size? Is it my service definition? Is this something in WCF?

Thanks


I think that it is problem with MaxStringContentLength property from reader quotas. Its default value is indeed 8192. You can change the value in binding configuration:

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding name="LargeString">
        <readerQuotas maxStringContentLength="16000" />
      </binding>
    </webHttpBinding>
  </bindings>
</system.serviceModel>

Reference this binding configuration in your endpoint configuration:

  <endpoint address="..." contract="..." binding="webHttpBinding" bindingConfiguration="LargeString" />

In case of WCF 4.0 you can omit name in binding definition and it should be used as default configuration for all webHttp endpoints.


I can think of a reasons without knowing it. Maybe you exceed the maximum message length? This can be set in your App.Config file.

If you have a vast amount of data to transfer you could either use streaming or build your own API just like cursors work in SQL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜