none
WCF. “The remote server returned an unexpected response: (400) Bad Request”. Configuration Error RRS feed

  • Question

  • Hello,

    I have WebService (WCF) working in a Windows 2003 server and with .Net Framework 3.5.

    The WebService has been working fine lately, excepte forcalls with a greater volume of data.

    The returned error is: “The remote server returned an unexpected response: (400) Bad Request”

    I have found what seems to be the solution, which is to add:

       
    1. In the Web.config (server) file: Make the values higher maxBufferPoolSize="8000000" maxReceivedMessageSize="8000000" and the readerquotas in <wsHttpBinding>.
    2. In the App.config (client) file: Give the size volumes and the quotes highe values in <wsHttpBinding>.
    3. Add <httpRuntime maxRequestLength="2147483647" /> in <system.web>.

    When I apply just sections 1 and 2 (sizes and quotas), I still get the error (400) Bad request.

    Afterwards, when I also apply section 3 <httpRuntime maxRequestLength...> , I get the following error:

    The content type text/html; charset=utf-8 of the response message does not
    match the content type of the binding (application/soap+xml; charset=utf-8). If
    using a custom encoder, be sure that the IsContentTypeSupported method is
    implemented properly
    . The
    first 1024 bytes of the response were:
    '<html>     
    <head>         
    <title>Configuration Error</title>         
    <style>           body
    {font-family:"Verdana";font-weight:normal;font-size:
    .7em;color:black;}           
    p {font-family:"Verdana";font-weight:normal;color:black;margin-nbsp;          b
    {font-family:"Verdana";font-weight:bold;color:black;margin-nbsp;          H1 {
    font-family:"Verdana";font-weight:normal;font-size:18pt;color:red
    }           H2 {
    font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon
    }           pre {font-family:"Lucida
    Console";font-size:
    .9em}           .marker
    {font-weight: bold; color: black;text-decoration:
    none;}           .version
    {color: gray;}          
    .error {margin-bottom:
    10px;}           .expandable
    { text-decoration:underline; font-weight:bold; color:navy; cursor:hand;
    }         
    </style>     
    </head>        <body
    bgcolor="white">               
    <span><H1>Server Error in '/SatDataService' Application.<hr
    width=100% size=1
    color=silver></H1>               
    <h2> <i>Configuration Error'
    ;

    After some hours struggling with this, I am still not capable of spotting the error in the web-config. Configuration.

    I am attaching the complete web.config to see if you can give me a hand.

    Thanks!

    Albert

    <?xml version="1.0"?>
    <configuration>
    	<configSections>
    		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
    					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				</sectionGroup>
    			</sectionGroup>
    		</sectionGroup>
        <!--Custom configuration sections-->
        <section name="SatService.Logging" type="SatService.Config.Logging" allowLocation="true" allowDefinition="Everywhere"/>
    
      </configSections>
    	<appSettings/>
    	
      <connectionStrings>
      <add name="CFCentralConnectionString" connectionString="Data Source=MOBILESERVER\MOBDEV;Initial Catalog=CFCentral;Persist Security Info=True;User ID=sa;Password=12345"
       providerName="System.Data.SqlClient" />
     </connectionStrings>
    
      <!--LogLevels: None, All, Debug, Info, Error, Fatal-->
      <SatService.Logging LogFileName="SatDataService.txt" LogPath="c:\antay\logging\v.2.8\SatDataService"
                                         LogLevel="All"/>
    
    
      <system.web>
    		<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" >
    			<assemblies>
    				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
    		</compilation>
    	    <httpRuntime maxRequestLength="2147483647" />
    	  
    		<pages>
    			<controls>
    				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			</controls>
    		</pages>
    		<httpHandlers>
    			<remove verb="*" path="*.asmx"/>
    			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    		</httpHandlers>
    		<httpModules>
    			<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</httpModules>
    	</system.web>
    	<system.codedom>
    		<compilers>
    			<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    				<providerOption name="CompilerVersion" value="v3.5"/>
    				<providerOption name="WarnAsError" value="false"/>
    			</compiler>
    			<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    				<providerOption name="CompilerVersion" value="v3.5"/>
    				<providerOption name="OptionInfer" value="true"/>
    				<providerOption name="WarnAsError" value="false"/>
    			</compiler>
    		</compilers>
    	</system.codedom>
    	<system.serviceModel>
    		<bindings>
    			<wsHttpBinding>
    				<binding name="wsHttpBinding" closeTimeout="00:01:00"  
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
    					maxBufferPoolSize="8000000" maxReceivedMessageSize="8000000"
    
                        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:10:00"
                            enabled="false" />
    					<security mode="Message">
    						<transport clientCredentialType="Windows" proxyCredentialType="None"
                                realm="" />
    						<message clientCredentialType="Windows" negotiateServiceCredential="true"
                                algorithmSuite="Default" establishSecurityContext="false" />
    					</security>
    				</binding>
    			</wsHttpBinding>
    		</bindings>
    		<services>
    			<service name="SatDataService" behaviorConfiguration="ServiceBehavior">
    				<!-- Service Endpoints -->
    				<endpoint address="" binding="wsHttpBinding" contract="ISatDataService">
    					<identity>
    						<dns value="localhost"/>
    					</identity>
    				</endpoint>
    				<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    			</service>
    		</services>
    		<behaviors>
    			<serviceBehaviors>
    				<behavior name="ServiceBehavior">
    					<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
    					<serviceMetadata httpGetEnabled="true"/>
    					<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
    					<serviceDebug includeExceptionDetailInFaults="false"/>
    				</behavior>
    				<behavior name="ThrottlingIssue">
    					<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances ="2147483647"/>
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    	</system.serviceModel>
    </configuration>

    Sunday, March 18, 2012 1:12 PM

Answers

  • Thanks JAXN

    That's it!!

    This was the configuration problem. Problem solved.

    Also the "400 Bad Request" was solved by adding bindingConfiguration="wsHttpBinding" at the endpoint.

    <endpointaddress=""binding="wsHttpBinding"bindingConfiguration="wsHttpBinding"contract="ISatDataService">

    Thanks for everything.

    I have attached the complete web.config in case anybody needs it.

    • Marked as answer by Alramos Sunday, March 18, 2012 8:03 PM
    Sunday, March 18, 2012 8:03 PM

All replies

  • Hi Alramos

    The value of your maxRequestLength is too large.

    The value for the property 'maxRequestLength' is not valid. The
    value must be inside the range 0-2097151


    Regards,

    JAXN


    MCTS: .NET Framework 4, Service Communication Applications

    Sunday, March 18, 2012 1:27 PM
  • Thanks JAXN

    That's it!!

    This was the configuration problem. Problem solved.

    Also the "400 Bad Request" was solved by adding bindingConfiguration="wsHttpBinding" at the endpoint.

    <endpointaddress=""binding="wsHttpBinding"bindingConfiguration="wsHttpBinding"contract="ISatDataService">

    Thanks for everything.

    I have attached the complete web.config in case anybody needs it.

    • Marked as answer by Alramos Sunday, March 18, 2012 8:03 PM
    Sunday, March 18, 2012 8:03 PM