【问题标题】:Large file uploads via WSHttpBinding in WCF通过 WCF 中的 WSHttpBinding 上传大文件
【发布时间】:2012-05-02 16:05:47
【问题描述】:

我正在使用 WSHttpBinding 开发 WCF 文件上传器。我希望上传大约 10 mb 的文件(不是在那个游戏上玩精确的游戏,但不会让文件变得更大)。一切都很好,最高可达 5mb。之后,我开始收到 HTTP 500 错误。

我的绑定设置如下:

wsBinding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
wsBinding.MaxBufferPoolSize = 52428800;
wsBinding.MaxReceivedMessageSize = 13631488;
wsBinding.ReceiveTimeout = new TimeSpan(0, 3, 0);

我的 httpRuntime maxRequestLength 在 web.config 中是 20480kb

我的请求如下所示:

POST http://mywebsite/FileUploader.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://namespace/UploadPhoto"
Content-Length: 13979476
Host: mywebsite
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:fil="http://namespace">
   <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://namespace/IFileUploaderSvc/UploadPhoto</wsa:Action></soap:Header>
   <soap:Body>
      <fil:UploadPhoto>
         <fil:AuthorizationToken>(Password)</fil:AuthorizationToken>
         <fil:ProgramName>AProgram</fil:ProgramName>
         <fil:FileName>bigolefile.jpg</fil:FileName>
         <fil:File>(base 64 file data)</fil:File>
      </fil:UploadPhoto>
   </soap:Body>
</soap:Envelope>

我使用 WSHttpBinding,而不是 WebHttpBinding,这一点非常重要。 提前致谢, 安德鲁

【问题讨论】:

标签: wcf file-upload wcf-binding


【解决方案1】:

尝试在 WSHttpBinding 绑定中为 messageEncoding 属性使用 TextMessageEncodingBindingElement 或 MtomMessageEncodingBindingElement。

例如,下面的 sn-p 使用 TextMessageEncodingBindingElement。 messageEncoding="Text" http://msdn.microsoft.com/en-us/library/ms733742.aspx

  <wsHttpBinding>
    <binding name="wsHttpWithMessageSecurity" messageEncoding="Text"
             closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
             sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"  textEncoding="utf-8"
                useDefaultWebProxy="true"
                allowCookies="false">

      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
                    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2015-02-13
    • 2010-10-04
    相关资源
    最近更新 更多