需要帮助:“远程服务器返回意外响应:(400) 错误请求。”

发布于 2024-11-02 10:15:50 字数 2625 浏览 1 评论 0原文

我有一个 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>

应用程序.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>

I have a WCF service that has been working fine for some time now, and I decided to add something to it. All of the old stuff works just as it should and the new stuff works for smaller transfers from the client to the host. However, it blows up with a "(400) Bad Request" when the client tries to send large strings to the host. Without changing anything, the host can send items that are just as large or larger to the client with no problem.

I've looked around on here and other sites, and while I've found people with the same problem, their solutions (increasing app.config sizes and lengths) have not yielded any successes for my problem.

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淤浪 2024-11-09 10:15:50

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

如果您遇到问题,请参阅其他 stackoverflow 主题。请参阅这篇博客文章介绍了如何在服务端进行一般设置;正如您可以想象的那样,这与您在客户端上完成的方式类似。

其次,有可能与安全相关。如果是这样,您也许可以通过查看以下文章来解决问题:

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

第三,简单地将“错误请求”报告为错误消息是没有用的。 :-) 请参阅我的回答 WCF not deserializing JSON input有关如何改进跟踪、调试和详细信息功能的详细步骤,以便您可以更好地处理服务端和客户端到底出了什么问题。

希望这有帮助!

First, the "maxReceivedMessageSize" on the client is used only when client receives messages (responses), so in your case you don't have to setup MaxReceivedMessageSize on the client at all; it will never be used. You do need to set it up on the service side.

See other stackoverflow topics on this if you have trouble. See this blog post on how to set this up on the service side in general; it is similar to how you have done it on the client end, as you can imagine.

Second, it is a possibility that this is security-related. In case it is, you might be able to solve the problem by looking at these articles:

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

Third, simply reporting a "bad request" as an error message is useless. :-) Please see my answer at WCF not deserializing JSON input for detailed steps on how you can improve your tracing, debugging, and details capabilities so that you can have a better handle on what exactly is going wrong on both the service and client end.

Hope this helps!

负佳期 2024-11-09 10:15:50

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

Have you tried an HTTP POST? You can send a lot more data with a POST than a GET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文