I got an issue when I was sending large files to WCF REST service using custom SharePoint MultipleBaseAddressWebServiceHostFactory. The error displayed as
“Entity Request too Large” Response Code: 413
You cannot override the settings in web.config because factory it self creates the dynamic end points so web.service changes can’t be used unless you remove the factory class and do it the conventional way.
Solution that worked for me:
You basically need to extend the below classes:
Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory
Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHost
public class CustomMultipleBaseAddressWebServiceHostFactory : Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory
{
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new CustomMultipleBaseServiceHost(serviceType, baseAddresses);
}
}
public class CustomMultipleBaseServiceHost : Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHost
{
public CustomMultipleBaseServiceHost(Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{
}
protected override void OnOpening()
{
base.OnOpening();
System.Diagnostics.Debug.Assert(false);
foreach (ServiceEndpoint endpoint in this.Description.Endpoints)
{
Binding binding = endpoint.Binding;
if (binding is WebHttpBinding)
{
var web = binding as WebHttpBinding;
web.MaxBufferSize = Int32.MaxValue;
web.MaxReceivedMessageSize = Int32.MaxValue;
}
var myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxStringContentLength = Int32.MaxValue;
binding.GetType().GetProperty(“ReaderQuotas”).SetValue(binding, myReaderQuotas, null);
}
}
}
Now instead of using default Microsoft class in the svc file we will use our custom dll reference.
<%@ ServiceHost Language=”C#”
Service=”Custom.Assembly.Classname,$SharePoint.Project.AssemblyFullName$”
CodeBehind=”CustomClass.cs”
Factory=”CustomMultipleBaseAddressWebServiceHostFactory, $SharePoint.Project.AssemblyFullName$” %>
Do an IISRESET and you will be able to send large files
Reference article:
Recent Comments