1
votes

I have created a WCF service which receives String (Text/Json) as a request, but the problem is it is only able to receive String length of 65536 (String.Length). I have tried below (binding maxReceivedMessageSize="2147483647") by googling but there is no change it is only able to receive 65536 of String.Length size only not more that. I am newbee to the dotNet and WCF word, can someone help me to send large data to this service (I wanted to send around 10MB of data to my WCF service).

   My Server Config:

   <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="[my-service-name]">
            <endpoint address="http://localhost:8005/MyService"
                  binding="webHttpBinding"
                  contract="[my-service-contract-name]"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647"
            maxBufferPoolSize="2147483647">
              <readerQuotas maxDepth="32"
              maxArrayLength="2147483647"
              maxStringContentLength="2147483647"/>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <startup> 
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
      </startup>
    </configuration>


    My Service:

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "MyService")]
        void MyService(String input)
        {
            Console.WriteLine("Request data = " + input.Length);
        }



Client Config:    

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="name-here" maxReceivedMessageSize="2147483647">
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior-here">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
2

2 Answers

1
votes

binding attribute for your service is set to webHttpBinding and you are adding attributes like maxReceivedMessageSize under basicHttpBinding. I believe it is just defaulting to the webHttpbinding attributes. I would recommend, create a binding under your httpBinding and make all the desired changes maxReceivedMessageSize under your new binding and tie it your service with the name of the binding as below :

  <basicHttpBinding>
    <binding name="testMessageBinding" maxReceivedMessageSize="30000000" openTimeout="00:00:02" receiveTimeout="00:00:02" sendTimeout="00:00:02" closeTimeout="00:00:02">
          <readerQuotas maxDepth="32"
          maxArrayLength="2147483647"
          maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>

Hope this helps and also read the below link to get more knowledge on custom binding, system-provided etc if you have not looked at the link

https://docs.microsoft.com/en-us/dotnet/framework/wcf/system-provided-bindings

0
votes
In your config, please add
"<dataContractSerializer maxItemsInObjectGraph="2147483647"/>"

Service Config:
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Client Config:
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>