0

I am getting an error

A Web exception occurred while attempting to issue the request. The remote server returned an error: (413) Request Entity Too Large.:

when trying to upload a file to a Sharepoint site from an ASP.Net Web Application. User adds selects a file via an ASP.Net File Upload control and the code below uploads it to Sharepoint. The file I am trying to upload is ~250k (i.e. not very large).

The code is as follows:

public string SharepointWebClientSOAPPost(Uri webService, string SOAPAction, string contentType, string postData, NetworkCredential networkCredential = null, string webProxy = "", NetworkCredential webserviceCredentials = null)
{
    try
    {
        using (WebClient client = new WebClient())
        {
            if (string.IsNullOrEmpty(webProxy) && webserviceCredentials != null)
            {
                client.Proxy = new WebProxy(new Uri(webProxy));
                client.Proxy.Credentials = webserviceCredentials;
            }
            if (networkCredential != null)
            {
               client.Credentials = networkCredential;
            }

            client.Headers.Add(HttpRequestHeader.ContentType, contentType);
            client.Headers.Add("SOAPAction", SOAPAction);

            // Apply ASCII Encoding to obtain the string as a byte array.
            var byteArray = Encoding.ASCII.GetBytes(postData);

            // Upload the input string using the HTTP 1.0 POST method.
            var responseArray = client.UploadData(webService, "POST", byteArray);

            // Decode and return the response.
            var response = Encoding.ASCII.GetString(responseArray);
            return response; 
        }
    }
    catch(Exception ex)
    {
        //etc.
    }
}

I have the following set in the web.config

<httpRuntime maxRequestLength="1024000" />

It works fine if I use a text file that is a few k, so I think the basic idea is right (the SOAP message is formatted ok and the URL is correct). However I am told by the person running the SP site that it is configured to accept documents of up to 50MB in size.

Any ideas where I can start looking for problems?

Max
  • 6,821
  • 3
  • 43
  • 59
glosrob
  • 6,631
  • 4
  • 43
  • 73

1 Answers1

1

Your code use WCF to upload file and not ASP.NET for this you must configure web.config maxReceivedMessageSize like this:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxReceivedMessageSize="10485760">

      </binding>
    </basicHttpBinding>
  </bindings>  
</system.serviceModel>
Max
  • 6,821
  • 3
  • 43
  • 59
  • Apologies for delay in my response - but this does not work (same error). The website is not hosting the service and as such I don't think the error is in 'receiving' but rather in 'sending' – glosrob Oct 10 '14 at 11:47
  • 2
    See [this](http://stackoverflow.com/questions/24009527/solved-wcf-the-remote-server-returned-an-error-413-request-entity-too-large) and [this](http://stackoverflow.com/questions/884235/wcf-how-to-increase-message-size-quota) and [this](http://stackoverflow.com/questions/24930058/file-upload-the-remote-server-returned-an-error-413-request-entity-too-large) – Max Oct 10 '14 at 13:30