By default, the WCF values for maxBufferSize and maxReceivedMessageSize are both 65536 (64K). If you send a request to a document service in Microsoft Dynamics AX and the message size exceeds this value, you’ll see a cryptic error that says something like: “The remote server returned an error: (400) Bad  Request.” You may also see an error message that references the maxReceivedMessageSize property.

 

To fix this problem, increase the binding properties maxBufferSize and maxReceivedMessageSize.  These properties are part of the <bindings> section in the app.config and web.config. Both parameters must be changed on the both the client side in the app.config and on the server side in the web.config. To change these properties, you can edit the config files directly or go to Basic Setup > AIF > Services and click the Configure button to open the service configuration editor. Here are some links that cover this aspect of WCF:

 

MSDN: http://msdn.microsoft.com/en-us/library/ms733135.aspx

Blog: http://geekswithblogs.net/niemguy/archive/2007/12/11/wcf-maxstringcontentlength-maxbuffersize-and-maxreceivedmessagesize.aspx

 

These are the relevant binding sections of app.config:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_FreeTextInvoiceService" closeTimeout="00:01:00"

                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="565536" maxBufferPoolSize="524288" maxReceivedMessageSize="565536"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

                    useDefaultWebProxy="true">

                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                    <security mode="TransportCredentialOnly">

                        <transport clientCredentialType="Windows" proxyCredentialType="None"

                            realm="" />

                        <message clientCredentialType="UserName" algorithmSuite="Default" />

                    </security>

                </binding>

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="http://dynamicsvm.contoso.com/MicrosoftDynamicsAXAif50/freetextinvoiceservice.svc"

                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_FreeTextInvoiceService"

                contract="FreeTxtInvoiceWebService.FreeTextInvoiceService"

                name="BasicHttpBinding_FreeTextInvoiceService" />

        </client>

    </system.serviceModel>

</configuration>

 

These are the relevant binding sections of web.config:

<system.serviceModel>

    <bindings>

      <basicHttpBinding>

        <binding name="basicHttpBindingWindowsAuth"

          maxBufferSize="565536"

          maxReceivedMessageSize="565536">

          <security mode="TransportCredentialOnly">

            <transport clientCredentialType="Windows" />

          </security>

        </binding>

      </basicHttpBinding>

    </bindings>

 

<service behaviorConfiguration="serviceBehaviorConfiguration"

        name="Microsoft.Dynamics.IntegrationFramework.Service.FreeTextInvoiceService">

        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingWindowsAuth"

          bindingNamespace="http://schemas.microsoft.com/dynamics/2008/01/services"

          contract="Microsoft.Dynamics.IntegrationFramework.Service.FreeTextInvoiceService" />

      </service>

 

In addition to changing these properties, you might also want to look at the transportMode property if your messages are very large. By default, this property is set to Buffered for the document services in AX. More relevant links about this property are:

 

MSDN: http://msdn.microsoft.com/en-us/library/ms731913.aspx

MSDN: http://msdn.microsoft.com/en-us/library/ms789010.aspx

 

MSDN Forum: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f00037f1-02e1-4e1c-b6ed-03fe134f3460/

MSDN Blog: http://blogs.msdn.com/drnick/archive/2006/03/31/565558.aspx

 

There are many considerations when it comes to message size and services such as limits in IIS, WCF configuration options, etc. Let me know if this resolves your message size issues or if you come across any other tips that worked in your particular installation.