需要帮助: "The remote server returned an unexpected response: (400) Bad Request."



我有一个运行良好的WCF服务,现在我决定给它添加一些东西。所有旧的东西都可以正常工作,新的东西可以从客户端到主机进行较小的传输。然而,当客户端试图向主机发送大字符串时,它会出现"(400)Bad Request"。在不改变任何东西的情况下,主机可以发送同样大或更大的项目给客户端,没有问题。

我在这里和其他网站上看了看,虽然我发现有人有同样的问题,但他们的解决方案(增加app.config的大小和长度)并没有对我的问题产生任何成功。

web . config

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
            <behavior  name="Throttled">
                <serviceThrottling
                    maxConcurrentCalls="1000"
                    maxConcurrentSessions="1000"
                    maxConcurrentInstances="1000" />
                <serviceMetadata
                    httpGetEnabled="true"
                    httpGetUrl="" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

app.config

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
             allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
             messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
             useDefaultWebProxy="true">
                <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                 maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                     realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="---HostingSiteURL---/Service.svc"
         binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
         contract="SimSyncServiceReference.IService" name="BasicHttpBinding_IService" />
    </client>
</system.serviceModel>

首先,客户端上的"maxReceivedMessageSize"仅在客户端接收消息(响应)时使用,因此在您的情况下,您根本不必在客户端上设置maxReceivedMessageSize;它永远不会被使用。你需要在服务端设置它。

如果您有问题,请参阅其他stackoverflow主题。请参阅这篇关于如何在服务端设置这一功能的博文;您可以想象,这与您在客户端所做的类似。

第二,一种与安全相关的可能性。如果是的话,您可以通过阅读这些文章来解决这个问题:

http://msdn.microsoft.com/en-us/library/bb628618.aspxhttp://msdn.microsoft.com/en-us/magazine/cc163570.aspx#S6http://msdn.microsoft.com/en-us/library/ms733130.aspx

第三,简单地将"错误请求"报告为错误消息是没有用的。:-)请参阅我在WCF不反序列化JSON输入的回答,了解如何改进跟踪,调试和详细功能的详细步骤,以便您可以更好地处理服务端和客户端究竟出了什么问题。

希望这对你有帮助!

您尝试过HTTP POST吗?使用POST可以发送比GET更多的数据。

最新更新