我创建了一个简单的 WCF 休息端点并将其部署到在 IIS 下运行的 Sharepoint - 80。
该服务接受带有 JSON 内容的 POST 请求。当post请求的内容不超过65536字节时它工作正常。对于任何较大的帖子,服务器会用
进行响应413请求实体太大
64k 似乎是 IIS 中默认的上传限制。为了增加限制,我想添加一个
web.config
并设置 maxReceivedMessageSize
参数。
但是,当我将以下
web.config
添加到服务的主目录中时:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="ExtendedMaxSize"
maxBufferSize="999999" maxReceivedMessageSize="999999" />
</webHttpBinding>
</bindings>
<services>
<service name="SharePointProject1.Service1" behaviorConfiguration="">
<endpoint address="http://localhost/_vti_Bin/testproject/sharepointproject1.svc"
binding="webHttpBinding"
bindingConfiguration="ExtendedMaxSize"
contract="SharePointProject1.IService1" />
</service>
</services>
</system.serviceModel>
</configuration>
服务停止运行并抛出错误
A registration already exists for http://localhost/_vti_Bin/testproject/sharepointproject1.svc
如何更改服务配置以提高上传限制?
PS:我进行了广泛的研究,发现许多链接都指向更改
web.config
中的设置。我尝试更改标准 Sharepoint web.config
,这对我的服务没有任何影响。
请检查您的客户端配置以确保绑定配置具有相同的属性:
maxReceivedMessageSize="2147483647"
增加Web服务的MaxReceivedMessageSize值来解决 这个问题。然而,这可能会变得棘手,因为有两个 不同的 MaxReceivedMessageSize 参数:
最大接收消息大小 System.ServiceModel.Configuration.BasicHttpBindingElement 最大接收消息大小 System.ServiceModel.Channels.HttpTransportBindingElement
下面的这个配置将增加MaxReceivedMessageSize System.ServiceModel.Configuration.BasicHttpBindingElement
<basicHttpBinding> <binding name="basicHttpBinding_Portal" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647">
您应该增加 MaxReceivedMessageSize System.ServiceModel.Channels.HttpTransportBindingElement 以及:
<customBinding> <binding closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00"> <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" useDefaultWebProxy="true"
transferMode =“缓冲”/>
以上内容来自此博客:WCF服务不接受超过64KB的文件。