gpt4 book ai didi

wpf - 上传大型 xml 到 WCF REST 服务 -> 400 错误请求

转载 作者:行者123 更新时间:2023-12-02 21:01:20 25 4
gpt4 key购买 nike

我一直在尝试寻找这个错误,但到目前为止还没有成功。

所以我的客户端上有一个带有此 web.config 的服务

  <system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.mywebsite.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="ServiceBehavior" name="UploadService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="IUploadService">
<identity>
<dns value="http://www.mywebsites.com/" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" maxReceivedMessageSize="4194304">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>

在客户端我有这个配置

  <system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IUploadService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:30:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://www.mywebsite.com/UploadService.svc"
binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService"
name="WSHttpBinding_IUploadService">
<identity>
<dns value="http://www.mywebsite.com/" />
</identity>
</endpoint>
</client>

我正在上传这样的文件:-

        using (Stream stream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read))
{
try
{
using (UploadServiceClient upc = new UploadServiceClient())
{
upc.UploadFile(stream);
}

}
catch (Exception exc)
{

}
}

对于小文件,它工作正常,但对于大型 XML 文件,这会失败并显示 400 Bad Request。我可以做什么来更改这些设置以传输大型 XML 文件?

感谢您的帮助和时间

更新客户端app.config

  <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_IUploadService" receiveTimeout="00:20:00"
bypassProxyOnLocal="true" maxBufferSize="4194304" maxReceivedMessageSize="4194304"
messageEncoding="Mtom" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.mywebsite.com/UploadService.svc"
binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService"
name="basicHttpBinding_IUploadService">
<identity>
<dns value="http://www.mywebsite.com/" />
</identity>
</endpoint>
</client>

最佳答案

您应该查看服务是否具有与客户端相同的 maxReceivedMessageSize="4194304"以及 XML 是否确实小于设置的 4,194,304 字节限制。 WCF 默认 maxReceivedMessageSize 为 64K。

更新:

我注意到您的配置显示正在为 basicHttpBinding 配置客户端,但该配置仅显示 wsHttpBinding。 wsHttpBinding 配置将被 WCF 忽略,因为它与 basicHttpBinding 无关。如果客户端配置文件没有 basicHttpBinding 元素,则在 .NET 4 中将使用默认元素。如果这是真的,那么您将遇到上述 64K 限制。

关于wpf - 上传大型 xml 到 WCF REST 服务 -> 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5779394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com