简体   繁体   English

wcf服务远程服务器返回错误(400)错误的请求

[英]wcf service the remote server returned an error (400) bad request

I have a windows application that calls WCF service. 我有一个Windows应用程序,调用WCF服务。 I'm getting 400 Bad Request error in some clients.(Some clients I don't get error.) I increased maxReceivedMessageSize but it didn't work. 我在某些客户端中收到400 Bad Request错误。(某些客户端我没有错误。)我增加了maxReceivedMessageSize,但是没有用。

I increased maxReceivedMessageSize and other parameters. 我增加了maxReceivedMessageSize和其他参数。

Client Side app.config: 客户端app.config:

<bindings>
  <wsHttpBinding>
    <binding name="BasicHttpBinding_IAracRandevuWS"
     closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000"
      maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
    <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
        algorithmSuite="Default" establishSecurityContext="true" />
      </security>

    </binding>
  </wsHttpBinding>
</bindings>

WCF Service app.config: WCF服务app.config:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="BasicHttpBinding_IAracRandevuWS"
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
      allowCookies="false" bypassProxyOnLocal="false"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceSecurityAudit auditLogLocation="Application" serviceAuthorizationAuditLevel="Failure" messageAuthenticationAuditLevel="Failure" suppressAuditFailure="true" />
  </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

How does the client generate the configuration file? 客户端如何生成配置文件? Which way you use to call the service, adding service reference or ChannelFactory? 您使用哪种方式调用服务,添加服务引用或ChannelFactory?
The wshttpbinding configuration does not well applied in the wshttpbinding, since we use the protocol mapping to host the service without using Bindingconfiguration property. 由于我们使用协议映射来托管服务而不使用Bindingconfiguration属性,因此在http:// binding中不能很好地应用wshttpbinding配置。

<protocolMapping>
  <add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>

Therefore, the default Clientcredentialtype is windows credential, and the security mode is message by default. 因此,默认的Clientcredential类型为Windows凭据,安全模式默认为message。
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding
We need to explicitly provide the windows credential on the client side. 我们需要在客户端上显式提供Windows凭据。

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
            client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";

In order to test this, please do not use Fiddler, and call it from another computer in Console application by using add service reference. 为了对此进行测试,请不要使用Fiddler,而是使用添加服务引用从控制台应用程序中的另一台计算机上调用它。
Feel free to let me know if the problem still exists. 随时让我知道问题是否仍然存在。

It was a network issue. 这是一个网络问题。 After update switch, the problem has been solved. 更新切换后,问题已解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF服务:远程服务器返回了意外的响应:(400)错误的请求 - WCF Service: The remote server returned an unexpected response: (400) Bad Request WCF:远程服务器返回错误:(400)错误的请求 - WCF:The remote server returned an error: (400) Bad Request (400)错误的请求-&gt;远程服务器返回错误:(400)错误的请求 - (400) Bad Request -> The remote server returned an error: (400) Bad Request 远程服务器返回错误:(400)错误请求? - The remote server returned an error: (400) Bad Request? 远程服务器返回错误(400)错误的请求 - the remote server returned an error (400) bad request WCF远程服务器返回了意外的响应:(400)错误的请求 - WCF The Remote Server Returned an Unexpected Response: (400) Bad Request 远程服务器返回意外响应:(400)错误请求,WCF - The remote server returned an unexpected response: (400) Bad Request, WCF C#WCF“ System.Net.WebException:远程服务器返回错误:(400)错误的请求。” - C# WCF “System.Net.WebException: The remote server returned an error: (400) Bad Request.” WCF REST POST JSON-远程服务器返回错误:(400)错误的请求 - WCF REST POST JSON - The remote server returned an error: (400) Bad Request 调用服务引用会导致“远程服务器返回错误:(400)错误请求”错误 - Calling a Service reference results in a “The remote server returned an error: (400) Bad Request” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM