【问题标题】:wcf upload stream - The remote server returned an unexpected response: (400) Bad Requestwcf 上传流 - 远程服务器返回意外响应:(400) 错误请求
【发布时间】:2013-01-13 02:01:21
【问题描述】:

我调查了很多类似的问题,但我无法解决我的问题!

我正在尝试向服务器发送一个 XML 文件,并通过一个函数以 XML 文件的形式获得响应。

我可以发送最大 48Kb 的 XML 文件,但不能发送更大的文件!

在开发我的网络服务和客户端时,我使用了this link

另外,我对 ISS 设置做了一些修改,如下:

cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 10485760

appcmd.exe set config "Default Web Site" -section:system.webServer/serverRuntime /uploadReadAheadSize:"10485760"  /commit:apphost

我在服务 web.config 文件中添加了<httpRuntime targetFramework="4.5" maxRequestLength="10485760" useFullyQualifiedRedirectUrl="true" executionTimeout="36000"/>

<system.web> <httpRuntime maxRequestLength="10485760"/> </system.web> 在客户端的 app.config 文件中

我在服务的web.config文件中实现了绑定和服务配置,如下:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" closeTimeout="10:01:00"
      openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00"
      maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
      transferMode="Streamed" messageEncoding="Text">
      <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="Service">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
      contract="IService" />
  </service>
</services>

在 App.config 中的客户端配置中:

<bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService" closeTimeout="10:01:00"
                openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00"
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647" transferMode="Streamed"
                messageEncoding="Text">
                <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
            <binding name="BasicHttpsBinding_IService">
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
    </bindings>

您知道为什么我无法发送大小超过 48KB 的文件吗?

【问题讨论】:

  • 您的客户是否有不同的 WCF 调用程序集?还是客户端程序集直接调用WCF服务?
  • 发送文件 > 48k 时出现什么错误?
  • 我在客户端应用程序中添加了 WCF 服务作为服务引用我收到错误“远程服务器返回意外响应:(400) 错误请求”
  • 通常当 maxRequestLength 配置不正确时会出现此错误,但看起来您做得正确。您确定您也在使用该服务的 IIS Web 应用程序上配置了 maxRequestLength?
  • 我的服务在默认网站下运行。但默认网站下还有其他网络服务。他们可以冲突吗?为了在 ISS 上配置 maxRequestLength,我使用了 cmets cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 10485760 appcmd.exe set config "Default Web Site" -section:system.webServer/serverRuntime /uploadReadAheadSize:"10485760" /commit:apphost 就像我一样调查uploadReadAheadSize指定maxRequestLength

标签: c# wcf web-services iis-7 streaming


【解决方案1】:

我在 web.cofing 文件中添加了下面的代码,问题就解决了:D

  <protocolMapping>
  <add binding="basicHttpBinding" scheme="http" bindingConfiguration="BasicHttpBinding_IService"/>
</protocolMapping>

【讨论】:

    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    相关资源
    最近更新 更多