WCF WebServiceHostFactory MaxReceivedMessageSize configuration

旧时模样 提交于 2019-11-29 12:50:40

I managed to get this working by setting the 3 settings below on the endpoint binding in the OnOpening method of my WebServiceHost:

protected override void OnOpening()
{
  base.OnOpening();

  foreach (var endpoint in Description.Endpoints)
  {
    var binding = endpoint.Binding as WebHttpBinding;
    if (binding != null)
    {
      const int fiveMegaBytes = 5242880;
      binding.MaxReceivedMessageSize = fiveMegaBytes;
      binding.MaxBufferSize = fiveMegaBytes;
      binding.MaxBufferPoolSize = fiveMegaBytes;
    }
  }
}

I need a large buffer size because I can't enable streaming.

Ok, for those of you that are looking for a solution to the above problem - I simply made some changes to my web.config file and hosted the service in my asp.net website.

I changed the <system.serviceModel> section of my web config to the following - this allows for 'Large Message Binding' where the max length of the post is specified in the appropriate section of the config file.

<system.serviceModel>
<bindings>
  <webHttpBinding>
    <binding name="largeMessageBinding" maxBufferPoolSize="5242880" maxReceivedMessageSize="5242880" transferMode="Buffered">
      <readerQuotas maxStringContentLength="5242880" maxArrayLength="5242880" maxBytesPerRead="5242880" />
    </binding>
  </webHttpBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="largePostEndpointBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="CDS.UI.Resources.Services.PalladiumBehavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="CDS.UI.Resources.Services.PalladiumBehavior"
   name="CDS.PalladiumService.Palladium">
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="largePostEndpointBehavior"
              bindingConfiguration="largeMessageBinding" contract="CDS.PalladiumService.IPalladium" />
  </service>
</services>

</system.serviceModel>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!