locked
problem while uploading Upload Large filed using Rest Service(WebHttpBinding) to sharepoint library RRS feed

  • Question

  • Hi I am getting Bad Request Error(400) when try to upload files using Rest service to SharePoint library  in this case service call is failing,for small files it is working fine(service get called Properly).Could you please help me out?

    Followings are my implementation for front end service call  and WCF service configuration

     

      private static T NewMethod<T>()
            {
                WebHttpBinding webbind = new WebHttpBinding();
                webbind.MaxReceivedMessageSize = webbind.MaxBufferPoolSize = webbind.MaxBufferSize= int.MaxValue;
                webbind.ReceiveTimeout = webbind.OpenTimeout= new TimeSpan(0, 15, 0);
                webbind.MaxBufferSize = 2147483647;
                webbind.MaxReceivedMessageSize = 2147483647;
                webbind.MaxBufferPoolSize = 2147483647;
                webbind.ReaderQuotas.MaxStringContentLength = webbind.ReaderQuotas.MaxArrayLength = int.MaxValue;
                WebHttpBehavior behv = new WebHttpBehavior();
                behv.DefaultOutgoingRequestFormat = System.ServiceModel.Web.WebMessageFormat.Json;
                ChannelFactory<T> servFact = new ChannelFactory<T>(webbind, new EndpointAddress("http://localhost:6430/InboundCommHub.svc"));
                servFact.Endpoint.Behaviors.Add(behv);

                T servClient = servFact.CreateChannel();
                return servClient;
            }

         

            protected void Button2_Click(object sender, EventArgs e)
            {
                List<Files> fl = new List<Files> {
                    new Files(){Contents=FileUpload1.FileBytes,FileName =FileUpload1.FileName},
               
                    new Files(){Contents=FileUpload2.FileBytes,FileName =FileUpload2.FileName }
        
                };


                Complaint complain = new Complaint()
                {
                    ComplaintDescription = "Test Complaint from SharePoint",
                    FirstName = "Aniruddha",
                    LastName = "Bhattt",
                    Documents = fl.ToArray()

                };
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    IInboundCommHub servClient = NewMethod<IInboundCommHub>();
                    servClient.SubmitComplaintsToTempStore(complain);
                    (servClient as ICommunicationObject).Close();
                });

            }

    Web.config is

    <services>
          <service name="InboundCommunicationHub.InboundCommHub" behaviorConfiguration="ServiceBehavior">
            <endpoint address=""  binding="webHttpBinding"  bindingName="webBinding"
                                   contract="InboundServiceHelper.IInboundCommHub"
                                  behaviorConfiguration="web"></endpoint>
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <binding name="webBinding" maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647"
                     transferMode="Streamed" bypassProxyOnLocal="true" useDefaultWebProxy="false"
                     sendTimeout="00:20:00" closeTimeout="00:20:00" receiveTimeout="00:20:00">
              <readerQuotas  maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647"/>
              <security mode="None" />
            </binding>
          </webHttpBinding>


        </bindings>


    Thursday, July 10, 2014 8:18 AM

Answers

All replies

  • Did you check this 

    http://stackoverflow.com/questions/6491696/maximum-file-upload-size-in-sharepoint

    Thursday, July 10, 2014 8:29 AM
  • My problem is not coming from sharepoint.....problem is for large file the sevice call get failed......with 400 bad requset
    Thursday, July 10, 2014 9:03 AM
  • Hello,

    Have you increased the upload size limit in sharepoint? You may also increase the length in web.config file of your web application.

    Please refer this for more info:

    http://blogs.technet.com/b/praveenh/archive/2012/11/16/issues-with-uploading-large-documents-on-document-library-wss-3-0-amp-moss-2007.aspx


    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Thursday, July 10, 2014 9:57 AM
    Moderator
  • Hi ,again my problem is not at SharePoint end ,for large document service invocation get failed....... I have already increased the size service web.config

    <services>
          <service name="InboundCommunicationHub.InboundCommHub" behaviorConfiguration="ServiceBehavior">
            <endpoint address=""  binding="webHttpBinding"  bindingName="webBinding"
                                   contract="InboundServiceHelper.IInboundCommHub"
                                  behaviorConfiguration="web"></endpoint>
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <binding name="webBinding" maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647"
                     transferMode="Streamed" bypassProxyOnLocal="true" useDefaultWebProxy="false"
                     sendTimeout="00:20:00" closeTimeout="00:20:00" receiveTimeout="00:20:00">
              <readerQuotas  maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647"/>
              <security mode="None" />
            </binding>
          </webHttpBinding>


    Thursday, July 10, 2014 10:23 AM
  • Hello,

    >FileUpload1.FileBytes,FileName =FileUpload1.FileName

    You may now try to convert byte to stream and then try:

    debugmode.net/2011/05/01/uploading-file-to-server-from-asp-net-client-using-wcf-rest-service/

    http://stackoverflow.com/questions/9700269/the-remote-server-returned-an-error-400-bad-request-uploading-less-2mb-file

    Let us know your result


    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help


    Friday, July 11, 2014 7:00 AM
    Moderator
  • Hemendra many thanks but ...the way you have proposed is it possible to attache multiple documents  ?which is required in my case...................
    Saturday, July 12, 2014 6:46 PM
  • Hello,

    I think you should be able to do this. You need to loop all files and convert into stream.

    if (UploadImages.HasFiles)
      {
        foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
           {
            //rest of the code    
          }
       }

    http://spbreed.wordpress.com/2013/10/10/sharepoint-multi-file-upload-control-with-metadata-using-uploadify-and-httphandler/


    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Monday, July 14, 2014 5:06 AM
    Moderator