1

I'm building custom WCF Rest service for Sharepoint 2010. Main task of service is to download and upload some files to/from Sharepoint. Download is working as expected, but when uploading file larger than 64Kb I get following error :

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Stack trace :

System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
System.ServiceModel.Channels.HttpInput.GetMessageBuffer()
System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& requestException)
System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, ItemDequeuedCallback callback)
System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
System.ServiceModel.PartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state)
System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

So my first guess was to increase maximum message size through custom configuration as follows :

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Project.Poc.StorageServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Project.Poc.IStorageService" behaviorConfiguration="Project.Poc.StorageServiceBehavior">
        <endpoint binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="Project.Poc.IStorageService"/>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="StreamedRequestWebBinding"
                 sendTimeout="00:05:00"
                 openTimeout="00:05:00"
                 receiveTimeout="00:05:00"
                 maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 transferMode="StreamedRequest">
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

After applying this, deploying my WSP and doing IIS reset error was still there. Same HTTP 400 with above information from WCF trace. So somehow my web.config configuration is not good because WCF service is not using it?

Upload files that are smaller then 64KB is working as expected.

Also this is My IStorageService.cs definition :

namespace Project.Poc
{
    [ServiceContract]
    public interface IStorageService
    {
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "/Download?path={path}")]
        Stream DownloadFile(string path);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/Upload?path={path}")]
        void UploadFile(string path, Stream content);
    }
}

And also StorageService.svc in ISAPI folder where my web.config is also :

<%@ ServiceHost Language="C#" Debug="true" Service="Project.Poc.StorageService, Project.Poc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d2ed6a8d86479f52"  CodeBehind="StorageService.svc.cs"  Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

I tried every other variation of web.config that I found googling but with no luck. What can be cause of this? Any help is more than welcome.

Also if you need any other part of the source code, just let me know. I will update my question.

Thank you in advance!

rjovic
  • 1,207
  • 2
  • 16
  • 37
  • Make sure to increase the maxRequestLength using the httpRunTime element in your web.config – Rajesh Apr 16 '13 at 15:40
  • No luck with that also.. – rjovic Apr 16 '13 at 15:49
  • What is the file size that you are trying to upload? Also enable tracing on your WCF Rest service and check the trace file. If possible inspect the raw request. – Rajesh Apr 16 '13 at 16:10
  • Also please check this link that describes on how to host a WCF rest service with sharepoint 2010 : http://blog.karstein-consulting.com/2012/01/21/walkthrough-create-simple-wcf-web-service-for-sharepoint-2010-with-visual-studio-2010/ – Rajesh Apr 16 '13 at 16:11
  • Around 80Kb. Tnx, I'll checkout the link that you provided – rjovic Apr 16 '13 at 16:19

1 Answers1

0

I'd review your client config - to be sure binding configuration has same attribute

maxReceivedMessageSize="2147483647".

Also, I'd try to add to your bindings (both client and service)

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

If both of this will not help - try to use SvcTraceViewer to find out where the error comes from (client when sending, server, ...)

evgenyl
  • 7,837
  • 2
  • 27
  • 32
  • Errors come from server. Also I can't do anything with the client side because I'm creating HTTP request using WebRequest class... Or I'm missing something? Your approach is for SOAP if I'm correct. This is rest service, to be consumed by other platforms as well, not only .net – rjovic Apr 16 '13 at 15:52
  • Yes, missed it - take a look on this answer: http://stackoverflow.com/questions/1439952/unable-to-set-maxreceivedmessagesize-through-web-config – evgenyl Apr 16 '13 at 16:46