Sharepoint自定义WCF Rest服务没有使用maxReceivedMessageSize



我正在为Sharepoint 2010构建自定义WCF Rest服务。服务的主要任务是从Sharepoint下载和上传一些文件。下载按预期工作,但当上传文件大于64Kb时,我得到以下错误:

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.

堆栈跟踪:

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)

所以我的第一个猜测是通过自定义配置增加最大消息大小,如下所示:

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

应用这个之后,部署我的WSP和做IIS重置错误仍然存在。与WCF跟踪的上述信息相同的HTTP 400。所以我的网。配置配置不好,因为WCF服务没有使用它?

上传小于64KB的文件可以正常工作。

这也是我的IStorageService.cs定义:

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);
    }
}

还有StorageService。svc在ISAPI文件夹,我的web。配置也是:

<%@ 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" %>

我尝试了所有其他的web版本。配置,我找到谷歌,但没有运气。这是什么原因呢?非常欢迎你的帮助。

如果您还需要源代码的任何其他部分,请让我知道。我将更新我的问题。

提前感谢!

我会检查您的客户端配置-以确保绑定配置具有相同的属性

maxReceivedMessageSize="2147483647" .

另外,我会尝试添加到您的绑定(客户端和服务)

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

如果这两个都没有帮助-尝试使用SvcTraceViewer找出错误来自何处(客户端发送时,服务器,…)

相关内容

  • 没有找到相关文章

最新更新