【问题标题】:how to increase MaxReceivedMessageSize when calling a WCF from vb.net从 vb.net 调用 WCF 时如何增加 MaxReceivedMessageSize
【发布时间】:2015-01-12 09:18:48
【问题描述】:

我在搜索 1 天的数据时使用 Wcf,但如果我搜索 30 天的数据,则会出现以下错误。

已超出传入邮件的最大邮件大小配额 (65536)。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

Server stack trace: 
   at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
   at System.ServiceModel.Channels.HttpInput.GetMessageBuffer()
   at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
   at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IToursGdsService.getBatchAvailability(getBatchAvailabilityRequest request)
   at ToursGdsServiceClient.IToursGdsService.getBatchAvailability(getBatchAvailabilityRequest request)

Inner Exception:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

我的 Service.config 文件有以下代码。

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="conString" connectionString="Server=.;Database=test;User ID=test;Password=test123"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    <customErrors mode="Off"></customErrors>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" >
      <serviceActivations>
        <add relativeAddress="TourGDSService.ToursGdsService.svc" service="TourGDSService.ToursGdsService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataServiceExtension">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="BasicHttpBinding_ToursGdsService" >
          <textMessageEncoding messageVersion="Soap12" />
          <httpTransport  maxReceivedMessageSize="2147483647"   maxBufferPoolSize="2147483647"  maxBufferSize="2147483647"/>

        </binding>
      </customBinding>
    </bindings>
    <extensions>
      <behaviorExtensions>
        <add name="metadataService" type="Thinktecture.ServiceModel.Extensions.Metadata.StaticMetadataBehaviorElement, Thinktecture.ServiceModel.Extensions.Metadata, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <services>
      <service behaviorConfiguration="metadataServiceExtension" name="TourGDSService.ToursGdsService">
        <endpoint address=""  binding="customBinding" bindingNamespace="http://giinfotech.com/app/05"
                  bindingConfiguration="BasicHttpBinding_ToursGdsService"    contract="IToursGdsService" />
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

  • 能否把客户端应用的配置文件也贴出来? (我认为这是来自服务应用程序的那个)
  • 您是否尝试使用giinfotech.com/app/05 服务?如果是这样,端点应该留在 而不是

标签: c# .net vb.net wcf


【解决方案1】:

也许问题与消息的总大小无关,而与消息元素的大小有关。

看看这个问题: WCF maxReceivedMessagesize and readerquotas

如果是这个问题,添加如下配置:

    <binding name="BasicHttpBinding_ToursGdsService" >
      <textMessageEncoding messageVersion="Soap12" />
      <httpTransport  maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  maxBufferSize="2147483647"/>
       <readerQuotas
          maxDepth="2147483647"
          maxStringContentLength="2147483647"
          maxArrayLength="2147483647"
          maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" />
    </binding>

另外,您可以尝试在绑定而不是 httpTransport 时添加属性 maxReceivedMessageSize、maxBufferPoolSize 和 maxBufferSize。

【讨论】:

  • 亲爱的 Cosmin 感谢您的回复。我在配置中也添加了 readerQuotas 仍然遇到同样的错误。
  • 如果将属性从httptransport移动到绑定是不是同样的错误?
  • 记住这个或类似的配置代码需要在服务器和消费客户端中
【解决方案2】:

如果你在代码中声明你的绑定,你的缓冲区大小可以在那里增加。

BasicHttpBinding q = new BasicHttpBinding(BasicHttpSecurityMode.None);
q.MaxBufferSize = 2147483646;
q.MaxBufferPoolSize = 2147483646;
q.MaxReceivedMessageSize = 2147483646;
q.ReaderQuotas.MaxArrayLength = 2147483646;
q.ReaderQuotas.MaxBytesPerRead = 2147483646;
q.ReaderQuotas.MaxDepth = 2147483646;
q.ReaderQuotas.MaxNameTableCharCount = 2147483646;
q.ReaderQuotas.MaxStringContentLength = 2147483646;

如果不是,您可以尝试执行池大小脚本,但我不确定 100% 会去哪里 (我会在评论中询问,但我还没有 50 个代表)

【讨论】:

  • 我只用基本的来演示你可以用你的自定义来做到这一点
猜你喜欢
  • 2011-12-10
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
相关资源
最近更新 更多