Search code examples
c#visual-studiowcf

Increasing maxBufferSize specifically for output


Right now I'm trying to create a WCF service to parse a group of json files. One function actually does the parsing and the other gathers the array of json strings. The array exceeds the Max Buffer Size, but when I plug it into the latter (within the function that creates the array) there's no error - only when I try to return the array itself. Here's what I mean:

Web2String.ServiceClient webServ = new Web2String.ServiceClient();
        string[] ip = new string[12];
        //MAKE SURE TO REPLACE THE KEY
        for (int i = 1; i < 13; i++)
        {
            if (mo == i || mo > 12 || mo < 1)
            {
                ip[i - 1] = webServ.GetWebContent("https://www.some.url");
            }
        }
        return ip;

Doesn't work, but

Web2String.ServiceClient webServ = new Web2String.ServiceClient();
        string[] ip = new string[12];
        //MAKE SURE TO REPLACE THE KEY
        for (int i = 1; i < 13; i++)
        {
            if (mo == i || mo > 12 || mo < 1)
            {
                ip[i - 1] = webServ.GetWebContent("https://www.some.url");
            }
        }
        return otherFunction(ip);

does.

Here is the binding I tried to add (that did nothing).

<bindings>
  <basicHttpBinding>
      <binding name="BasicHttpBinding_IService" maxBufferPoolSize="6000000"
        maxBufferSize="5000000" maxReceivedMessageSize="5000000" >
      </binding>
  </basicHttpBinding>
</bindings>

How should I handle this?

The bulk of the error message is as follows:

enter image description here

EDIT: I should also mention for clarity that otherFunction returns an array that's way, way below the buffer size.


Solution

  • It seems like that you're getting the error message from the service side. According to your error message & config, you've set the value for the limit of maxReceivedMessageSize and other settings. If you're not yet assigned that binding to your service endpoint, in this situation WCF will use the default value for maxReceivedMessageSize which is 65536.

    You need to assign your defined binding (wsBinding) to your endpoint(s) through the bindingConfiguration attribute of the endpoint element, as per following this:

    <endpoint address="" 
          binding="wsHttpBinding"
          bindingCongifuration="wsBinding"
          contract="PMSService.ThomoloshaDeclaration">