【问题标题】:Setting MaxReceivedMessageSize in the client of a wcf rest service在 wcf 休息服务的客户端中设置 MaxReceivedMessageSize
【发布时间】:2013-10-14 16:52:28
【问题描述】:

我有一个休息 WCF 服务,我使用控制台应用程序连接到该服务。控制台应用程序下载文件。小文件工作正常。对于较大的文件,我收到以下错误:

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

这是我在客户端控制台应用程序上的配置文件。

<configuration>     
<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding maxReceivedMessageSize="2000000"
                  maxBufferSize="2000000">
          <readerQuotas maxStringContentLength="2000000"/>
        </binding>
      </webHttpBinding>
    </bindings>
    </system.serviceModel>
</configuration>

WCF 配置如下:

    <webHttpBinding>
        <binding name="MyTestBinding" maxReceivedMessageSize="10000000" maxBufferPoolSize="10000000" maxBufferSize="10000000" transferMode="Buffered">
            <readerQuotas maxDepth="10000000" maxArrayLength="10000000" maxBytesPerRead="10000000" maxNameTableCharCount="10000000" maxStringContentLength="10000000" />
            <security mode="Transport">
                <transport clientCredentialType="None" />
            </security>
        </binding>
    </webHttpBinding>

我正在使用 WebChannelFactory 连接到服务。有什么问题?

【问题讨论】:

  • WCF 支持 MaxRecivedMessageSize 为 2147483647。您必须在客户端和服务端都设置它。我想查看您的 WCF 配置设置
  • 尝试将服务行为添加到您的服务配置中
  • 同时显示正在使用的端点。

标签: .net wcf rest


【解决方案1】:

尝试在您的客户端配置文件中为webHttpBinding 指定一个名称,并使用WebChannelFactory Constructor (String, Uri) 引用它。这需要一个字符串作为绑定配置名称和服务的 Uri:

<configuration>
  <system.serviceModel>
    <bindings>
      <webHttpBinding name="MyWebHttpBinding">
        <binding maxReceivedMessageSize="2000000"
                 maxBufferSize="2000000">

basicHttpBindinghttp 的默认绑定,因此除非您在客户端配置的protocolMapping 部分中覆盖了它,否则您将获得httpBinding 的默认值。

使用name 属性集,您可以获得这样的工厂实例:

WebChannelFactory<IContract> factory = new WebChannelFactory<IContract>("MyWebHttpBinding", new Uri("service address"));

【讨论】:

  • 谢谢。但是,我必须在创建工厂实例时提供绑定对象。该字符串是端点配置名称。
  • 我在我的 java 应用程序中使用 c# wcf 服务,在那里我配置了这个 MaxBufferSize
  • @R.Anandan - 这将在您的 Java 客户端的配置文件或代码中。我建议您将此作为新问题发布,并附上相关信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-01
  • 2011-01-28
  • 2010-12-26
  • 2011-05-27
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多