2

I got this error when trying to pass large byte[] to wcf service my IService Code:

[OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveFile")]
        SaveFileResult SaveFile(byte[] FileBytes, string FileName, decimal Filesize, string IntegrationSystem, string TellerIndentity, string SendingOfficeCode, string SendingArea);

Service Code:

public SaveFileResult SaveFile(byte[] FileBytes, string FileName, decimal Filesize, string IntegrationSystem, string TellerIndentity, string SendingOfficeCode, string SendingArea)
        {
            FileFactory _FileFactory = new FileFactory();
            string _strExt = Path.GetExtension(FileName);
            IFileDealer _IFileDealer = _FileFactory.GetFileDealer(_strExt);
            SaveFileResult _Result=_IFileDealer.SaveFile(FileBytes, FileName, Filesize, IntegrationSystem, TellerIndentity, SendingOfficeCode, SendingArea);
            return _Result;
        }

wcf service Config:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="CenterPostEntities" connectionString="metadata=res://*/DatabaseDesign.GRemModel.csdl|res://*/DatabaseDesign.GRemModel.ssdl|res://*/DatabaseDesign.GRemModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=TEST-SH\SQL2005;initial catalog=CenterPost;user id=sa;password=itsc;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="PermittedFastUploadSize"  value="1000000"/>
    <add  key ="GRemLog" value="d:\GRemLog"/>
    <add key="FileUploadPath" value="d:\FileUpload"/>
  </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.0" />
      <httpRuntime maxRequestLength="2097151" />
  </system.web>
  <system.serviceModel>
    <!--======================-->
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingSettings"  openTimeout="00:01:00" receiveTimeout="05:00:00" sendTimeout="05:00:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647777" messageEncoding="Text">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <!-- To avoid disclosing metadata information,
        set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes,
        set the value below to true.  Set to false before deployment
        to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--======================-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
   <serverRuntime enabled="true" uploadReadAheadSize="2147483647"  />
  </system.webServer>

Please any one help me to solve this problem i increased uploadReadAheadSize on iis7 but still not working i want to know why this code not working

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Eslam Totti
  • 125
  • 2
  • 13
  • 1
    check it out [Request Entity Too Large](http://stackoverflow.com/questions/14636407/maxreceivedmessagesize-not-fixing-413-request-entity-too-large) and this one [Request Entity Too Large](http://stackoverflow.com/questions/10122957/iis7-413-request-entity-too-large-uploadreadaheadsize) – Ravi Jan 02 '14 at 10:38
  • Can you add the endpoint config from the server? – rene Jan 02 '14 at 10:45
  • i added it but still not working – Eslam Totti Jan 02 '14 at 10:55

1 Answers1

4

The binding you've defined in your config file ("basicHttpBindingSettings") is not being used by the WCF service because you do not have an endpoint defined that uses it. With WCF 4.0+, if there are no endpoints defined in the config file, a default endpoint will be created (and out of the box, the binding will be basicHttpBinding with default values).

You have two ways to fix this.

First, you can make your binding definition the default by omitting the name attribute, like this:

<bindings>
  <basicHttpBinding>
    <binding openTimeout="00:01:00" receiveTimeout="05:00:00" 
             sendTimeout="05:00:00" maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647777" messageEncoding="Text">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>

This will then be the default configuration for basicHttpBinding.

The second option is to define an explicit endpoint and assign your binding configuration to it via the bindingConfiguration attribute, like this:

<services>
  <service name="<service name>">
    <endpoint address="" binding="basicHttpBinding"
              bindingConfiguration="basicHttpBindingSettings"
              contract="<fully qualified contract name>" />
  </service>
</services>

For more information on default endpoints and bindings, see A Developer's Introduction to Windows Communication Foundation 4.

Tim
  • 28,212
  • 8
  • 63
  • 76