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

时间:2019-07-11 09:59:45

标签: c# wcf

我有一个Windows应用程序,该应用程序调用WCF服务。我在某些客户端中收到400错误的请求错误。(某些客户端我没有错误。)我增加了maxReceivedMessageSize,但是没有用。

我增加了maxReceivedMessageSize和其他参数。

客户端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服务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"/>

2 个答案:

答案 0 :(得分:0)

客户端如何生成配置文件?您使用哪种方式调用服务,添加服务引用或ChannelFactory?
wshttpbinding配置不能很好地应用于wshttpbinding中,因为我们使用协议映射来托管服务而不使用Bindingconfiguration属性。

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

因此,默认的Clientcredential类型为Windows凭据,默认情况下安全模式为message。
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding
我们需要在客户端显式提供Windows凭据。

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

为了对此进行测试,请不要使用Fiddler,而是使用添加服务参考从控制台应用程序中的另一台计算机调用它。
随时让我知道问题是否仍然存在。

答案 1 :(得分:0)

这是网络问题。更新切换后,问题已解决。