0
votes

I have a windows application that calls WCF service. 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.

I increased maxReceivedMessageSize and other parameters.

Client Side 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:

<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
Also when I open fiddler and call WCF through windows application, I get no error. When I close fiddler, I get the bad request error. - dotnetcoder

2 Answers

0
votes

How does the client generate the configuration file? Which way you use to call the service, adding service reference or 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.

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

Therefore, the default Clientcredentialtype is windows credential, and the security mode is message by default.
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding
We need to explicitly provide the windows credential on the client side.

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.
Feel free to let me know if the problem still exists.

0
votes

It was a network issue. After update switch, the problem has been solved.