0

我正在开发一个可以上传和下载图片的网站。下载工作正常,没有问题,但同时上传的图片大于 16 KB 时出现问题,告诉我:“协议异常:错误 400 错误请求”。

这告诉我我必须在 XmlDictionaryReaderQuotas 中增加 MaxArrayLength 的大小,但我已经这样做了。

我将向您展示我的 webConfig:

客户:

<bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IServiceImage" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="4194304" maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="4194304" maxStringContentLength="4194304" maxArrayLength="4194304"
            maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

周转基金:

 <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IServiceImage" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false">
          <readerQuotas maxDepth="4194304" maxStringContentLength="4194304" maxArrayLength="4194304"
          maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
          <security mode="Message">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

任何想法?

编辑:我可以上传文件,直到它们小于 16KB,我找不到我必须处理该值以增加的地方。


听起来对于大文件,wcf 有一些问题,所以我必须将“encodeMessage”更改为 MTOM 并从 BasicHttpBindings 移动到 wsHttpBindings。顺便说一下,我的代码上出现了新问题。该死的。

客户端 WebConfig:

<bindings>

  <wsHttpBinding>
    <binding name="wsHttpBinding_IService1" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
      messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
      allowCookies="false">
      <readerQuotas maxDepth="4194304" maxStringContentLength="4194304"
        maxArrayLength="4194304" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

服务网络配置:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_IService1" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

             maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
      messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
      <!--messageEncoding="Text" textEncoding="utf-8" maxBufferSize="4194304" transferMode="Buffered" -->
      <readerQuotas maxDepth="4194304" maxStringContentLength="4194304"
        maxArrayLength="4194304" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>


<services>
  <service  name="WcfService.FileService" >
    <endpoint address="" binding="wsHttpBinding" contract="WcfService.IService1" />
  </service>
</services>
4

1 回答 1

0

听起来像是您想要使用流服务而不是缓冲的场景。

http://msdn.microsoft.com/en-us/library/ms733742.aspx

巧合的是,我正在努力实现自己。

于 2012-12-21T20:48:51.603 回答