I’ve been working quite a bit with custom WCF services in SharePoint 2010 and have found there’s quite a bit to it. The part that worries me is that there is a ton of information out there that is not always best for enterprise scenarios, like setting the site in IIS to anonymous just to get service calls working.
Anyway… I was trying to figure out why the reader quota settings weren’t getting applied to our services. We had the following debug code:
- SPWebService contentService = SPWebService.ContentService;
- contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
- SPWcfServiceSettings wcfServiceSettings = new SPWcfServiceSettings();
- wcfServiceSettings.ReaderQuotasMaxStringContentLength = Int32.MaxValue;
- wcfServiceSettings.ReaderQuotasMaxArrayLength = Int32.MaxValue;
- wcfServiceSettings.ReaderQuotasMaxBytesPerRead = Int32.MaxValue;
- wcfServiceSettings.MaxReceivedMessageSize = Int32.MaxValue;
- wcfServiceSettings.MaxBufferSize = Int32.MaxValue;
- wcfServiceSettings.ReaderQuotasMaxDepth = Int32.MaxValue;
- wcfServiceSettings.ReaderQuotasMaxNameTableCharCount = Int32.MaxValue;
- wcfServiceSettings.ReceiveTimeout = TimeSpan.MaxValue;
- contentService.WcfServiceSettings["MyService.svc"] = wcfServiceSettings;
This was placed in a feature scoped at the web application level, and the WSP was deploying to /ISAPI/CustomWcf/MyService.svc”. We we’re using SharePoint’s MultipleBaseAddressBasicHttpBindingServiceHostFactory factory, and if you are you don’t need to set anonymous in IIS. This factory applies your security settings as they are on the web application.
So why weren’t our WCF Service settings getting applied? If you check out this MSDN article, it doesn’t actually tell you what I figured out:http://msdn.microsoft.com/en-us/library/ff599489.aspx
The problem is that “MyService.svc” should actually be lower case: “myservice.svc”. It sounds silly, but that is what worked for me. The /CustomWcf/ folder part should be excluded.
If anyone is doing the same, here are a few tips on how such deployment strategy could be improved:
- The feature should really be at a farm level if it is modifying settings on the Content Service. There is one per farm.
- Feature Deactivation code should call contentService.WcfServiceSettings.Remove("myservice.svc");
- You SHOULD NOT just use Int32.MaxValue, but actually figure out your maximums and what exact properties you should apply them on. In my example I’m obviously trying to get a sample to work.
- Make sure your deactivation doesn’t break any other solution if you are resetting with this line: contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = 0;
Hope this helps!