加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 从vb.net调用WCF时如何增加MaxReceivedMessageSize

发布时间:2020-12-15 22:10:39 所属栏目:百科 来源:网络整理
导读:当我搜索1天数据时,我正在使用Wcf我得到了结果,但如果我搜索30天数据,我会收到以下错误. The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota,use the MaxReceivedMessageSize property on the appropr
当我搜索1天数据时,我正在使用Wcf我得到了结果,但如果我搜索30天数据,我会收到以下错误.

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.

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>

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读