none
The remote server returned an unexpected response: (400) Bad Request. RRS feed

  • Question

  • I am getting the following error message when uploading a file larger than 65k in size to WCF SharePoint 2010 web service.    If the file is less than 65k it works fine.  I built a custom web service to upload files into SharePoint and I adding that web service as a service reference to a custom web app that will upload the files.  Once I click the upload button which uses a method that in the WCF web serice, I get this error message, "The remote server returned an unexpected response: (400) Bad Request."

    My guess is that I do not have the system.serviceModel setup correctly.  Can someone provide a detailed example?


    My evironment is
    Windows 2008 R2 64bit.
    IIS 7.0
    Asp.Net 4.0
    SharePoint 2010

    My Interface Contract looks like...

    namespace SomeNameSpace
    {
                  [ServiceContract]
                  public interface IDocService
                  {

                           [OperationContract]
                           string PutDocument(byte[] fileToStore);
                  }

    }

     

     


    C# Developer
    • Moved by Mike Walsh FIN Monday, July 11, 2011 6:39 PM Neither a programming question nor a pre-SP 2010 question. Moving to SP 2010 Admin (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Monday, July 11, 2011 5:48 PM

Answers

  • I figured out what the problem was.... I had to do the following.

    Increase the file size limit on each system (IIS 7.5, Asp.net, WCF, and SharePoint).

     

    Tell SharePoint to increase its file size by following the steps below.

    Ø  As the SharePoint Site Administrator, access the SharePoint 2010 Management Shell by

    1.       On the Start menu, click All Programs.

    2.       Click Microsoft SharePoint 2010 Products.

    3.       Click SharePoint 2010 Management Shell.

    Ø  Then run the commands below.

    1.       get-PSSnapin - Registered

    2.       Add-PSSnapin Microsoft.SharePoint.Powershell

    3.       $ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

    4.       $ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647

    5.       $ws.Update()

    Tell Asp.Net to increase its file size by following the steps below.

    Ø  Edit all web.config files involved to add the element “<httpRuntime>”.  When you are done, your addition should look like the example below.

    o   2147483647 bytes is equal to 1.99 GB.

    <system.web>

                    <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000"/>

      

    </system.web>

    Tell IIS 7.0 and up to increase its file size by following the steps below.

    Edit all web.config files involved to add the element “<requestLimits>”.  When you are done, your addition should look like the example below.

     

     

    <system.webServer>

        <modules runAllManagedModulesForAllRequests="true"/>

        <security>

          <requestFiltering>

            <requestLimits maxAllowedContentLength="2147483647" />

          </requestFiltering>

        </security>

      </system.webServer>

     

    Tell WCF to increase its file size by following the steps below.

     

    Ø  On the service side web.config file, add the following code.  The <bindings> section if the most important section.  This section will increase the file size.

      <system.serviceModel>

        <services>

          <service name="MyService.IMyService">

            <endpoint address="" binding="basicHttpBinding" contract="MyService.IMyService" />

          </service>

        </services>

     

        <bindings>

          <basicHttpBinding>

                <binding hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"

                       maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Buffered"

                       messageEncoding="Text" textEncoding="utf-8" bypassProxyOnLocal="false" useDefaultWebProxy="true" >

                  <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647"/>

                </binding>

          </basicHttpBinding>

        </bindings>

     

        <behaviors>

          <serviceBehaviors>

            <behavior>

              <!-- 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>

     

     

     

     

     

     

     

    Ø  On the client side web.config file, add the following code.

    <system.serviceModel>

        <bindings>

          <basicHttpBinding>

            <binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00"

              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

              allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

              maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"

              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

              useDefaultWebProxy="true">

              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"

                maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

              <security mode="None">

                <transport clientCredentialType="None" proxyCredentialType="None"

                  realm="" />

                <message clientCredentialType="UserName" algorithmSuite="Default" />

              </security>

            </binding>

          </basicHttpBinding>

        </bindings>

        <client>

          <endpoint address="http://serviceAddress/MyService.svc" binding="basicHttpBinding"

            bindingConfiguration="BasicHttpBinding_IDocService" contract="MyService.IMyService"

            name="BasicHttpBinding_IMyService" />

        </client>

      </system.serviceModel>


    C# Developer
    • Marked as answer by hhoward Thursday, July 14, 2011 4:00 PM
    Thursday, July 14, 2011 4:00 PM

All replies

  • Hi,

    For this issue, you need to extend the timeout of the request.

    Please refer to:

    http://social.msdn.microsoft.com/Forums/eu/sharepointdevelopment/thread/e4a4f35f-d007-4f49-961b-35ddfcc03880

    Regards,

    Seven

    Thursday, July 14, 2011 8:07 AM
  • I figured out what the problem was.... I had to do the following.

    Increase the file size limit on each system (IIS 7.5, Asp.net, WCF, and SharePoint).

     

    Tell SharePoint to increase its file size by following the steps below.

    Ø  As the SharePoint Site Administrator, access the SharePoint 2010 Management Shell by

    1.       On the Start menu, click All Programs.

    2.       Click Microsoft SharePoint 2010 Products.

    3.       Click SharePoint 2010 Management Shell.

    Ø  Then run the commands below.

    1.       get-PSSnapin - Registered

    2.       Add-PSSnapin Microsoft.SharePoint.Powershell

    3.       $ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

    4.       $ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647

    5.       $ws.Update()

    Tell Asp.Net to increase its file size by following the steps below.

    Ø  Edit all web.config files involved to add the element “<httpRuntime>”.  When you are done, your addition should look like the example below.

    o   2147483647 bytes is equal to 1.99 GB.

    <system.web>

                    <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000"/>

      

    </system.web>

    Tell IIS 7.0 and up to increase its file size by following the steps below.

    Edit all web.config files involved to add the element “<requestLimits>”.  When you are done, your addition should look like the example below.

     

     

    <system.webServer>

        <modules runAllManagedModulesForAllRequests="true"/>

        <security>

          <requestFiltering>

            <requestLimits maxAllowedContentLength="2147483647" />

          </requestFiltering>

        </security>

      </system.webServer>

     

    Tell WCF to increase its file size by following the steps below.

     

    Ø  On the service side web.config file, add the following code.  The <bindings> section if the most important section.  This section will increase the file size.

      <system.serviceModel>

        <services>

          <service name="MyService.IMyService">

            <endpoint address="" binding="basicHttpBinding" contract="MyService.IMyService" />

          </service>

        </services>

     

        <bindings>

          <basicHttpBinding>

                <binding hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"

                       maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Buffered"

                       messageEncoding="Text" textEncoding="utf-8" bypassProxyOnLocal="false" useDefaultWebProxy="true" >

                  <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647"/>

                </binding>

          </basicHttpBinding>

        </bindings>

     

        <behaviors>

          <serviceBehaviors>

            <behavior>

              <!-- 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>

     

     

     

     

     

     

     

    Ø  On the client side web.config file, add the following code.

    <system.serviceModel>

        <bindings>

          <basicHttpBinding>

            <binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00"

              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

              allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

              maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"

              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

              useDefaultWebProxy="true">

              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"

                maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

              <security mode="None">

                <transport clientCredentialType="None" proxyCredentialType="None"

                  realm="" />

                <message clientCredentialType="UserName" algorithmSuite="Default" />

              </security>

            </binding>

          </basicHttpBinding>

        </bindings>

        <client>

          <endpoint address="http://serviceAddress/MyService.svc" binding="basicHttpBinding"

            bindingConfiguration="BasicHttpBinding_IDocService" contract="MyService.IMyService"

            name="BasicHttpBinding_IMyService" />

        </client>

      </system.serviceModel>


    C# Developer
    • Marked as answer by hhoward Thursday, July 14, 2011 4:00 PM
    Thursday, July 14, 2011 4:00 PM