我在 SharePoint 中托管了 WCF 服务,该服务前段时间运行良好,但现在无法运行,我不明白为什么会这样。如果文件小于 16Kb 没有错误,我尝试将文件发布到服务并得到错误 400(badrequest)。我改变了我的配置文件
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDocumentSetService" 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="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/_vti_bin/documentset.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDocumentSetService" contract="Sitronics.AFK.BoD.SharePoint.Services.Services.IDocumentSetService" name="BasicHttpBinding_IDocumentSetService" />
</client>
</system.serviceModel>
我需要在服务器端修改 maxArrayLength,我该怎么做?服务主机配置如下
public class DocumentSetServiceFactory : MultipleBaseAddressBasicHttpBindingServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
var sh = base.CreateServiceHost(serviceType, baseAddresses);
sh.Opening += sh_Opening;
return sh;
}
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
{
var sh = base.CreateServiceHost(constructorString, baseAddresses);
sh.Opening += sh_Opening;
return sh;
}
void sh_Opening(object sender, EventArgs e)
{
var sh = (ServiceHostBase)sender;
LoggingService.LogDebug("DocumentServiceHost:Opening");
if (sh.Description != null)
{
LoggingService.LogDebug("DocumentServiceHost:Description is not null");
foreach (var endPoint in sh.Description.Endpoints)
{
LoggingService.LogDebug(string.Format("DocumentServiceHost:FOR ENDPOINT {0}", endPoint.Address));
var bec = endPoint.Binding.CreateBindingElements();
var transport = bec.Find<TransportBindingElement>();
if (transport != null)
{
LoggingService.LogDebug(string.Format("DocumentServiceHost:TRANSPORT {0}",transport.Scheme));
transport.MaxReceivedMessageSize = 5242880;
transport.MaxBufferPoolSize = 5242880;
}
}
}
}
}