如何在从 vb.net 调用 WCF 时增加最大接收消息大小

本文关键字:增加 消息 WCF vb 调用 net | 更新日期: 2023-09-27 18:37:21

当我搜索 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.

我的服务配置文件具有以下代码。

<?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>

如何在从 vb.net 调用 WCF 时增加最大接收消息大小

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

看看这个问题: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。

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

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 次)