简体   繁体   English

自定义SharePoint 2010 WCF服务-如何设置MaxReceivedMessageSize参数

[英]Custom SharePoint 2010 WCF Service - How to set MaxReceivedMessageSize parameter

I have developped a custom WCF Web Service within a SharePoint 2010 Visual Studio empty project. 我已经在SharePoint 2010 Visual Studio空项目中开发了自定义WCF Web服务。

My web service is working well. 我的网络服务运行良好。 The problem is related to the size of the request I can send to this web service. 问题与我可以发送到此Web服务的请求的大小有关。 I have realized that is something around 300Kb. 我已经意识到大约300Kb。 If I go bigger than that, the service/client is sending me an exception. 如果我超出此范围,则服务/客户端向我发送异常。

I've looked around on the web and see that the MaxReceivedMessageSize setting may be my solution. 我在网上四处张望,发现MaxReceivedMessageSize设置可能是我的解决方案。 I've tried using a FeatureActivated method to set this information using this kind of request: 我尝试使用FeatureActivated方法通过以下请求设置此信息:

// increase maximum size of requests to this web service: http://msdn.microsoft.com/en-us/library/ff599489.aspx
SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
csomWcfSettings.MaxReceivedMessageSize = 10485760; // 10MB
contentService.WcfServiceSettings["PT-SP-P2S-DocumentCreator.svc"] = csomWcfSettings;
contentService.Update(); // access denied thrown here!

With that code, I have an Access denied (I'm actually the Site Collection Administrator). 使用该代码,我的访问被拒绝(我实际上是网站集管理员)。

I also know that this parameter may be set in the app.config of web service host but, in SharePoint, where to I need to change this parameter. 我也知道可以在Web服务主机的app.config中设置此参数,但是在SharePoint中,我需要在哪里更改此参数。

I think you should make this change in the web.config file of the Web Application in which the feature is activated. 我认为您应该在激活该功能的Web应用程序的web.config文件中进行此更改。 SharePoint provides APIs to make web.config changes. SharePoint提供了用于更改web.config的API。 In fact, using APIs to make changes to your web.config is preferred option because SharePoint uses Timer Job and makes same updates to all Web Front End servers in your environment. 实际上,首选使用API​​来更改web.config,因为SharePoint使用Timer Job并对环境中的所有Web前端服务器进行相同的更新。 There are 2 ways to make changes to web.config as described here: 如下所述,有2种方法可以更改web.config:

http://msdn.microsoft.com/en-us/library/ms460914.aspx http://msdn.microsoft.com/en-us/library/ms460914.aspx

In your case, since you want to make the change only when your feature is activated, you would take the API approach as documented here: http://msdn.microsoft.com/en-us/library/bb861909.aspx 在您的情况下,由于您只想在激活功能时进行更改,因此可以采用此处记录的API方法: http : //msdn.microsoft.com/zh-cn/library/bb861909.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM