首页 > 代码库 > wcf文件上传时碰到的配置问题

wcf文件上传时碰到的配置问题

1.远程服务器返回了意外相应:(413) Request Entity Too Large

修改客户端配置maxReceivedMessageSize="2147483647"

<bindings>
    <basicHttpBinding>
        <binding name="BasicHttpBinding_WcfService" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
            <security mode="None" />
        </binding>
    </basicHttpBinding>
</bindings>

并在服务端修改webconfig,加入binding节点并配置

 <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647" messageEncoding="Text" transferMode="Streamed" sendTimeout="00:10:00" >            </binding>


加入Services节点,并配置 name和contract(contract保持与服务的类相同)。

 <services>
      <service name="ResourceService.ResourceService">
        <endpoint address="" binding="basicHttpBinding"
          bindingConfiguration="LargeDataTransferServicesBinding" name="XXX" contract="ResourceService.IResourceService" />
      </service>
    </services>

2.二进制传输时由于wcf默认的传递数据大小仅为64K,会报:WCF 读取 XML 数据时,超出最大数组长度配额(16384)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxArrayLength 属性,可增加此配额。

修改客户端 ,加入readerQuotas。

 <binding name="BasicHttpBinding_IResourceService" maxReceivedMessageSize="2147483647" >
                <readerQuotas maxDepth="32" maxStringContentLength="20971520" maxArrayLength="20971520"
                       maxBytesPerRead="40960" maxNameTableCharCount="163840"/>
              </binding>


修改服务器端,加入readerQuotas

   <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647" messageEncoding="Text" transferMode="Streamed" sendTimeout="00:10:00" >
              <readerQuotas maxStringContentLength="20971520" maxArrayLength="20971520"/>
            </binding>

 

其他错误 可参考:http://blog.csdn.net/educast/article/details/4637246