none
WCF receives max string length 32767

    Question

  • Hi,

    I've a WCF service method to receive large string of length 47640. But it receives only the string of length 32767.

    How to receive my entire string of size 47640? Below is the configuration i used in WCF?

    Service Method:

    [OperationContract]

    string GetFileName(string attachedFile);

     

    Web.config

    <system.serviceModel>

        <services>

          <service name="TestWcfServiceLibrary.Service1" behaviorConfiguration="TestWcfServiceLibrary.Service1Behavior">

            <host>

              <baseAddresses>

                <add baseAddress = "http://localhost:8732/TestWcfServiceLibrary/Service1/" />

              </baseAddresses>

            </host>

            <endpoint address ="" binding="basicHttpBinding" contract="TestWcfServiceLibrary.IService1" bindingConfiguration="largeBuffer"/>

            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

          </service>

        </services>

        <behaviors>

          <serviceBehaviors>

            <behavior name="TestWcfServiceLibrary.Service1Behavior">

              <serviceMetadata httpGetEnabled="True"/>

              <serviceDebug includeExceptionDetailInFaults="False" />

            </behavior>

          </serviceBehaviors>

        </behaviors>

        <bindings>

          <basicHttpBinding>

            <binding name="largeBuffer">

              <readerQuotas

                            maxDepth="2147483647"

                            maxStringContentLength="2147483647"

                            maxArrayLength="2147483647"

                            maxBytesPerRead="2147483647"

                            maxNameTableCharCount="2147483647" />

              <security mode="None"></security>

            </binding>       

          </basicHttpBinding>

        </bindings>

      </system.serviceModel> 


    Anandhan.S
    Thursday, January 12, 2012 12:08 PM

All replies

  • Hello,

    The settings for quotas do not matter on the client.  Its the server you need to worry about. You need to specify the binding settings to use.  You cant just specify information in the binding and expect the endpoint to use it.  You must include the binding configuration name in the endpoint like this:

    Your above Webconfig settings seems fine and it should work. Vsn you verify,does the service reference properly updated?

    Feel free to contact in case of query.


    If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.
    • Marked as answer by Yi-Lun Luo Wednesday, January 18, 2012 9:21 AM
    • Unmarked as answer by Yi-Lun Luo Wednesday, January 18, 2012 9:21 AM
    Thursday, January 12, 2012 12:43 PM
  • Hi,

    I tested in SharePoint 2010 server (Windows Server 2008 R2) & in Local system (client) in both places i received the max string length 32767.

    unable to retrieve the entire string?


    Anandhan.S
    Saturday, January 21, 2012 6:13 AM
  • Hello,

    I am able to receive very large arrays by configuring the same readerQuota parameters as you did, with addition that I increased the following settings under binding configuration: maxBufferPoolSize, maxReceivedMessageSize. You haven't configured the last two settings so I suggest you try that. Example:

     

    <bindings>
          <wsHttpBinding>
            <binding name="EndPointWSHTTP" closeTimeout="00:01:00" openTimeout="00:01:00"
              receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
              transactionFlow="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="20480000" maxReceivedMessageSize="20480000" messageEncoding="Text"
              textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
              <readerQuotas maxDepth="20480000" maxStringContentLength="20480000" maxArrayLength="20480000"
                maxBytesPerRead="20480000" maxNameTableCharCount="20480000" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
              <security mode="Message">
                <message clientCredentialType="Certificate" negotiateServiceCredential="true"
                  algorithmSuite="Default" />
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>

    However it should present an exception if the string is too large, not truncate it.... Can you show us your GetFileName implementation?

     



    • Edited by dejancg Saturday, January 21, 2012 11:37 AM fixed typos
    Saturday, January 21, 2012 11:35 AM
  • I would recomend you you to enable WCF tracing to find out the root cause.Below link will help you to configure Tracing.

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

    Most of the time dataContractSerializer is the real culprit. You can try adding,<dataContractSerializer maxItemsInObjectGraph="2147483647" /> in to your Service behaviours i.e

    <serviceBehaviors>
            <behavior name="TestWcfServiceLibrary.Service1Behavior">
              <serviceMetadata httpGetEnabled="True"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>


    Lingaraj Mishra
    Monday, January 23, 2012 9:38 AM