WCF maxReceivedMessageSize 无法通过 HTTPS 工作

WCF maxReceivedMessageSize not working over HTTPS

我正在尝试使用 WCF 服务通过 HTTPS 通过 SSL 加密来接收大型 XML 消息。我的应用程序基于 .NET Framework 4.5 构建,并部署在 IIS 8.5 服务器上。

使用以下 Web.Config 配置,我能够通过 HTTP 接收大型 XML,但它在 HTTPS 上存在一些问题。 (HTTPS 通信已经工作正常,带有自签名证书和所有)。

   <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="5242880" maxBufferSize="5242880"/>
      </basicHttpBinding>

      <basicHttpsBinding>
         <binding maxReceivedMessageSize="5242880" maxBufferSize="5242880"/>
      </basicHttpsBinding>
    </bindings>

    <behaviors>   
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>

使用 SoapUI 进行一些测试,大文件仅在更新定义时通过 HTTPS 发送(即使 Web.Config 文件中没有任何更改)。

当外部系统(来自 SAP 的 TIBO/PI)调用我们的服务时,simplr 无法正常工作,并显示以下错误消息:

HTTP/1.1 413 请求实体太大 缓存控制:私有 服务器:Microsoft-IIS/8.0 X-AspNet-版本:4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcVkFMRVxDb2RpZ28tYnJhbmNoLW9uZGExLW9uZGEyLW1lcmdlXFN1cHBsaWVyRmluYW‌ 5jZS5XZWJTZXJ2aWNlc1xDb250cmF0b3Muc3Zj?= X-Powered-By:ASP.NET 日期:2015 年 4 月 9 日星期四 22:28:41 GMT 内容长度:0

那是因为您只有 basicHttpBinding 的配置,而没有 basicHttpsBinding 的配置。也为基于 SSL 的绑定创建默认配置:

   <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="5242880" maxBufferSize="5242880"/>
      </basicHttpBinding>
      <basicHttpsBinding>
        <binding maxReceivedMessageSize="5242880" maxBufferSize="5242880"/>
      </basicHttpsBinding>
    </bindings>

试试这个绑定(我明确指定了绑定的名称,所以在服务配置中使用它)

<basicHttpBinding>
    <binding maxReceivedMessageSize="10485760">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="10485760" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None"/>
    </binding>
</basicHttpBinding>
<basicHttpsBinding>
    <binding maxReceivedMessageSize="10485760">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="10485760" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None"/>
    </binding>
</basicHttpsBinding>

如果不行尝试添加

<system.webServer>
    <serverRuntime uploadReadAheadSize="2147483646"/>
</system.webServer>

给你配置。希望对你有帮助。