1

I have the following wcf service method which takes Attachment object and the Attachment class definition is:

    [DataContract]
    public class Attachment
    {
        [DataMember]
        public int AttachmentId { get; set; }
        [DataMember]
        public String DMSFileId { get; set; }
        [DataMember]
        public String FileName { get; set; }
        [DataMember]
        public int? FileSize { get; set; }
        [DataMember]
        public String FileSource { get; set; }
        [DataMember]
        public byte[] File { get; set; }
    }

And the method definition is :

[OperationContract]    
public int AddAttachment(DataTypes.Administration.Attachment attachment)
{
   return AttachmentBusinessLogic.AddAttachment(attachment);
}

When the method is called I get the following exception: The remote server returned an unexpected response: (413) Request Entity Too Large

Googling the error I came across many binding configuration but none of them worked not the maxReceivedMessageSize nor the readerQuotas.

Here is the web config of both the service and the client:

Service

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Client

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <behaviors>
          <endpointBehaviors>
            <behavior name="AdministrationBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_IAdministrationService" sendTimeout="00:05:00"
                     openTimeout="00:05:00"
                     receiveTimeout="00:05:00"
                     maxReceivedMessageSize="2147483647"
                     maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647">
                <readerQuotas maxArrayLength="2147483647"
                              maxStringContentLength="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:8001/AdministrationService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAdministrationService" contract="AdministrationService.IAdministrationService" name="BasicHttpBinding_IAdministrationService" behaviorConfiguration="AdministrationBehavior" />
    </client>
</system.serviceModel>

Any suggestion on how to overcome this exception please.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
A_Nabelsi
  • 2,524
  • 18
  • 21

3 Answers3

0

The place where you need to work on is the web config, you need to add service behaviours where you can set the size of data. For example like this,

  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="SilverlightWCFLargeDataApplication">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

if that does not work, post your web config here.Hope it helps.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Thanks, I already tried this configuration but it did not work, maybe I am missing something I updated the post and added the web configs. Thanks for your help. – A_Nabelsi Jan 14 '13 at 07:35
  • Post your service web.config – Sajeetharan Jan 14 '13 at 11:59
  • I already did, I posted the web config of the service which is under the title Service. – A_Nabelsi Jan 14 '13 at 13:43
  • what is this? is that all you have in your web config? where are the service configuration and endpoint configuration? – Sajeetharan Jan 14 '13 at 13:51
  • That is all I have in the service web config, I created a new web application and added new service there is nothing there but what I provided in the post, should I add the configuration manually? – A_Nabelsi Jan 14 '13 at 14:20
  • Yes. You need to provide the configuration, it should have automatically generated. I suggest you to add manually. – Sajeetharan Jan 14 '13 at 15:07
0

I managed to solve it by following the steps to configure wcf web config file in another post.

configuring WCF wtih tag

Community
  • 1
  • 1
A_Nabelsi
  • 2,524
  • 18
  • 21
0

Use this settings

 <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"  messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" >
          <readerQuotas  maxStringContentLength="525288"></readerQuotas>
        </binding>
      </basicHttpBinding>
Telan Niranga
  • 437
  • 3
  • 10