在wcf rest服务的客户端中设置MaxReceivedMessageSize

时间:2013-10-14 16:52:28

标签: .net wcf rest

我有一个其他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连接到该服务。可能有什么不对?

1 个答案:

答案 0 :(得分:2)

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

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

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

设置name属性后,您就可以获得这样的工厂实例:

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