WCF Error - Unexpected Response: (400) Bad Request

I am having trouble finding an answer to this problem. Most of the similar messages are usually captured by setting some maximum size parameters in the web.config file. However, none of these suggestions fixed my problem.

To give a little more background, I am migrating the asmx web service to the WCF web service hosted on Windows Azure. This problem occurred during testing. If I transfer a small number of transactions to my web service in one call, it works fine. This error occurs when the transaction size is around 50-60 (transactions). Serialized in xml, the file size is about 300 KB, so it’s nothing insanely big. But he is inclined to lean toward the problem of size.

Also, by enabling WCF tracing, I found the following exception:

System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages has been exceeded (65536). To increase the quota, use the MaxReceivedMessageSize property in the corresponding binding element.

in System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException (String message, HttpStatusCode statusCode, String statusDescription)

in System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded ()

in System.ServiceModel.Channels.HttpInput.ReadBufferedMessage (stream inputStream)

in System.ServiceModel.Channels.HttpInput.ParseIncomingMessage (exception and amp; requestException)

in System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived (HttpRequestContext context, Action callback)

, , , web.config, :

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
    <behavior name="MetadataEnabled">
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceMetadata httpGetEnabled="true"/>
      <useRequestHeadersForMetadataAddress>
        <defaultPorts>
          <add scheme="http" port="8081"/>
          <add scheme="https" port="444"/>
        </defaultPorts>
      </useRequestHeadersForMetadataAddress>
      <dataContractSerializer maxItemsInObjectGraph="111024000"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled">
    <endpoint name="HttpEndpoint"
              address=""
              binding="wsHttpBinding"
              bindingConfiguration="wsHttp"
              contract="Bandicoot.CORE.IRepricer" />
    <endpoint name="HttpMetadata"
              address="contract"
              binding="mexHttpBinding"
              bindingConfiguration="mexBinding"
              contract="Bandicoot.CORE.Stack" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Core"/>
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttp" maxReceivedMessageSize="111024000" 
             messageEncoding="Text" maxBufferPoolSize="111024000" 
             textEncoding="UTF-8">
      <readerQuotas maxBytesPerRead="111024000"
                    maxArrayLength="111024000"
                    maxStringContentLength="111024000"/>
      <security mode="None"/>
    </binding>
  </wsHttpBinding>
  <mexHttpBinding>
    <binding name="mexBinding"/>
  </mexHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

- - web.config, ?

!

: app.config

<bindings>
<basicHttpBinding>
    <binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="14194304" maxBufferPoolSize="14194304" maxReceivedMessageSize="14194304"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
        <readerQuotas maxDepth="1000" maxStringContentLength="111024000"
            maxArrayLength="111024000" maxBytesPerRead="1024000" maxNameTableCharCount="111024000" />
        <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
    </binding>
</basicHttpBinding>

: :

        <client>
        <endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE"
            name="BasicHttpBinding_CORE" />
    </client>

: basicHttpBinding - :

      <basicHttpBinding>
    <binding name="basicHttp" maxReceivedMessageSize="111024000"
             messageEncoding="Text" maxBufferPoolSize="111024000"
             textEncoding="UTF-8">
      <readerQuotas maxArrayLength="111024000" maxBytesPerRead="111024000" maxStringContentLength="111024000"/>
      <security mode="None" />
    </binding>
  </basicHttpBinding>

      <service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled">
    <endpoint binding="basicHttpBinding"
              bindingConfiguration="basicHttp"
              contract="Bandicoot.CORE.IRepricer" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              bindingConfiguration="mexBinding"
              contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/Core"/>
      </baseAddresses>
    </host>
  </service>

app.config :

        <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="100000000"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    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="http://localhost:92/CORE.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE"
            name="BasicHttpBinding_CORE" />
    </client>
+3
4

, , . , , , , . ? .

, .

, , , , , - , web.config? , , basicHttpBinding, web- wsHttpBinding.

, , . !

+1

maxReceivedMessageSize ( , , ) - app.config web.config:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttp" maxReceivedMessageSize="111024000" 
             messageEncoding="Text" maxBufferPoolSize="111024000" 
             textEncoding="UTF-8">
      <readerQuotas maxBytesPerRead="111024000"
                    maxArrayLength="111024000"
                    maxStringContentLength="111024000"/>
      <security mode="None"/>
    </binding>
  </wsHttpBinding>
  <mexHttpBinding>
    <binding name="mexBinding"/>
  </mexHttpBinding>
</bindings>
<client name="whatever">
    <endpoint name="HttpEndpoint"
        address=""
        binding="wsHttpBinding"
        bindingConfiguration="wsHttp"
        contract="Bandicoot.CORE.IRepricer" />
</client>
</system.serviceModel>

maxReceivedMessageSize 64 , .

+2

, .

, marc_s, maxReceivedMessageSize . - , 64 .

, , , () .

, - .

+1

, ""!

17-17 15:29.

"", "" , , . , , -.

. " " , hosts, Load Balancer, Single Server 80! " " , Load Balancer 81!

Service Endpoint Address " ", , Services.config , "Single Server" "Load Balanced Server", :

:

endpoint address="http://www.myserver.com:80/Services/MyService.svc"

:

endpoint address="http://www.myserver.com:81/Services/MyService.svc"

, , , . , " " , , 80, 81 , , . Please note that he could not call the service, he just could not bind user bindings!

Hope someone remembers this post the next time we produce a test service with custom bindings :)

0
source

Source: https://habr.com/ru/post/1774991/


All Articles