Upload greater than 8 MB streams through WCF Service

140 views Asked by At

I'm trying to upload photo(attachment stream) through window service , using REST configuration (webHttpBinding), but I get this exception
enter image description here

here is the binding configuration I used (I tried all of them and the error still as it )

      <webHttpBinding>
        <binding name="maxRequest" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode ="Transport"></security>
        </binding>

       
        <binding name="maxRequestBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"  >
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode ="Transport">
          </security>
          
        </binding>

        <binding name="BasicHttpBinding_IFileService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
          transferMode="Buffered" useDefaultWebProxy="true" 
          >
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

          <security mode ="Transport"></security>
        </binding>

I had also tried the solution for IIS posted here

https://techcommunity.microsoft.com/t5/iis-support-blog/solution-for-request-entity-too-large-error/ba-p/501134

however, all of the above doesn't work.

here is my endpoint behavior

      <endpointBehaviors>
        <behavior name="rest">
          <webHttp faultExceptionEnabled="true" helpEnabled="true"/>
          <dataContractSerializer maxItemsInObjectGraph="1365536" />
        </behavior>
      </endpointBehaviors>

here is the contract

enter image description here

and For more information the image size is just 100KB.

1

There are 1 answers

0
Ding Peng On BEST ANSWER

WCF default transmission message size is 64KB, you need to use MaxReceivedMessageSize to set the transmission message size.

<system.serviceModel>
    <services>

        <service name="ConsoleApp1.RawDataService" behaviorConfiguration="ServiceBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:8012/ServiceModelSamples/service"/>
                </baseAddresses>
            </host>

            <endpoint address=""
                      binding="webHttpBinding"
                      contract="ConsoleApp1.IReceiveData"
                      behaviorConfiguration="ESEndPointBehavior" bindingConfiguration="RestfullwebHttpBinding"/>
        </service>
    </services>
    <bindings>
        <webHttpBinding>
            <binding name="RestfullwebHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
            </binding>
        </webHttpBinding>
    </bindings>
    
    
    <behaviors>
        <endpointBehaviors>
            <behavior name="ESEndPointBehavior">
                <webHttp helpEnabled="true"/>
            </behavior>
        </endpointBehaviors>

        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata/>
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>

    </behaviors>

</system.serviceModel>

You need to apply RestfullwebHttpBinding to the endpoint.

enter image description here

Feel free to let me know if the problem persists.