WCF:协议异常-400不良请求



我正在开发一个可以上传和下载图片的网站。下载效果很好,没有问题,但是与此同时,上传的图片大于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>

WCF:

 <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遇到了一些问题,因此我必须将"编码"更改为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>

服务webconfig:

<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>

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

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

巧合的是,我正在为实施自己而努力。

相关内容

  • 没有找到相关文章

最新更新