locked
Strange Error STILL : The remote server returned an unexpected response: (400) Bad Request .net 4 WCF RRS feed

  • Question

  • User-1098991037 posted

    I am totally stumped with this issue I am having at the moment.I have been reading various articles and blogs for the last 2 days and made most of the recommended changes but im still having this issue. Basically I am passing an array object as a parameter from the client to the service,which then gives me the above error. I can process 200 records ok, but if I set it at 250 for example, it returns the 400 error. I have enabled tracing etc but nothing is being logged at all when it errors out. Both the client and service are running on the same environment (testing purposes) -windows 2008r2 I will show both config files and also how Im calling the service..any help is much appreciated!

    Client config

    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
      </configSections>
      <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <httpRuntime  executionTimeout="180" maxRequestLength="2147483647" />
      </system.web>
      <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="WSHttpBinding_FinHqclient" closeTimeout="00:25:00"
              openTimeout="00:25:00" receiveTimeout="10:50:00" sendTimeout="00:25:00"
              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
              useDefaultWebProxy="true" allowCookies="false">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <security>
                <transport realm="" />
              </security>
            </binding>
          </wsHttpBinding>
          <basicHttpBinding>
            <binding  maxBufferPoolSize="2147483647" name="test" maxBufferSize="2147483647"  maxReceivedMessageSize="2147483647" >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <endpointBehaviors>
            <behavior name="maxItemsInObjectGraphBehaviour">
              <dataContractSerializer maxItemsInObjectGraph="2147483646" />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <client>
          <endpoint address="http://server:8123/service.svc" behaviorConfiguration="maxItemsInObjectGraphBehaviour"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_FinHqclient"
            contract="sfgServ.FinHqclient" name="WSHttpBinding_FinHqclient">
            <identity>
              <servicePrincipalName value="host/local" />
            </identity>
          </endpoint>
        </client>
      </system.serviceModel>
    </configuration>

    Server Config:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    
      </configSections>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
            <listeners>
              <add name="traceListener"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData= "c:\log\Traces.svclog" />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />    
    <httpRuntime  executionTimeout="180" maxRequestLength="2147483647" />
      </system.web>
      <system.serviceModel>
        <diagnostics>
          <messageLogging logEntireMessage="true"  logMalformedMessages="true"
            logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <protocolMapping>
          <add scheme="http" binding="wsHttpBinding"/>
        </protocolMapping>
        <services>
          <service name="SFG.CRM2011.WebServiceFinHqFinHq.Service"  behaviorConfiguration="SFG.CRM2011.WebServiceFinHq.ServiceBehavior">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="SFG.CRM2011.WebServiceFinHq.BindConfig"  
                      contract="sfgServ.IClientFinHQ" behaviorConfiguration="SFG.CRM2011.WebServiceFinHq.wsServiceEndpointBehavior">
            </endpoint>
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" bindingConfiguration="higherMessageSize_MEX" address="mex" />
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="SFG.CRM2011.WebServiceFinHq.wsServiceEndpointBehavior">          
              <dataContractSerializer  maxItemsInObjectGraph="2147483646" />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="SFG.CRM2011.WebServiceFinHq.ServiceBehavior">
              <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
            <behavior >
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
              <!-- 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="true"/>
            </behavior>
          </serviceBehaviors>      
        </behaviors>    
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <bindings>
          <wsHttpBinding >
            <binding name="SFG.CRM2011.WebServiceFinHq.BindConfig"    maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <security mode="None">
                <transport clientCredentialType="None" />
                <message establishSecurityContext="false" />
              </security>
              <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
              <readerQuotas maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647" />
            </binding>        
          </wsHttpBinding>
          <mexHttpBinding>
            <binding name="higherMessageSize_MEX"  />                  
          </mexHttpBinding>
            <basicHttpBinding >
            <binding  maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <readerQuotas maxStringContentLength="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
       <security>
         <requestFiltering>
           <requestLimits maxAllowedContentLength="9000000" />
         </requestFiltering>
       </security>
     </system.webServer>
    </configuration>



    This is how I call this service from the client

    List<FUMStruct> fList = new List<FUMStruct>();
    
                for (int i = 0; i < 250; i++)
                {
                    var t = new FUMStruct();
                    t.clientID = "1234";
                    t.ClientCRMGUID = new Guid("9EACA7AE-FE7E-E211-956A-00505622E202");
                    t.CRMAccountCRMGUID = new Guid("A63D9ADC-0CFF-E211-94E9-00505622E202");
                    t.Balance = 200 + i;
                    fList.Add(t);
                }
                var serv = new FinHqclientClient();            
                serv.UpdateLastFUMGUID(fList.ToArray());


     

    Thursday, August 22, 2013 8:46 PM

Answers

  • User-1098991037 posted

    finally!!

    It was because there was a ‘name’ value in the binding,. Therefore the custom values we were setting weren’t being applied and it was loading the server defaults (not even sure where the ‘defaults’ for the different bindings are kept!)  I found this out by an article I read online and making a new service using basic binding only..which kept failing,until I removed the name then it started working! Then I had to figure out how to do it for wsHttpBinding because with that binding, if you don’t specify the name (and then obviously you cant reference the configuration) you get all sorts or security issues etc and the service doesn’t work..so the solution was to add another binding without the name property in it.

    The settings were only needed on the server side in the end,because i left the default client values (lower than the ones in the example above) and it still worked. Below is the full web.config..note how i had to default for both basicHttpbinding and wsHttpbinding

    <bindings>
          <wsHttpBinding >
            <binding ***name="problemWithValue"***    maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <security mode="None">
                <transport clientCredentialType="None" />
                <message establishSecurityContext="false" />
              </security>
              <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
              <readerQuotas maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647" />
            </binding>
            <binding     maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <security mode="None">
                <transport clientCredentialType="None" />
                <message establishSecurityContext="false" />
              </security>
              <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
              <readerQuotas maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647" />
            </binding>
          </wsHttpBinding>
          <mexHttpBinding>
            <binding name="higherMessageSize_MEX"  />                  
          </mexHttpBinding>
            <basicHttpBinding >
            <binding  maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <readerQuotas maxStringContentLength="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 3, 2013 7:49 PM

All replies

  • User-488622176 posted

    my 2 cents : set the 

    maxReceivedMessageSize

    at the server side too

    Monday, August 26, 2013 7:30 AM
  • User-1098991037 posted

    Sorry, looks like my server web.config didnt copy correctly...i have indeed set the maxReceivedmessagesize on the server but with no luck :(

    Monday, August 26, 2013 8:03 AM
  • User281315223 posted

    As it was suggested, the issue here may be the size of the response that is being returned back (250 records may be too large). You'll likely want these values to match on in the webServer area of your tag and consider adjusting the actual allowed length of the response as well : 

    <!-- IIS Specific Targeting (noted by the system.webServer section) -->
    <system.webServer>
       <security>
          <requestFiltering>
             <!-- This will handle requests up to 1024MB (1GB) -->
             <requestLimits maxAllowedContentLength="1048576000" />
          </requestFiltering>
       </security>
    </system.webServer>



    Monday, August 26, 2013 8:16 AM
  • User-1098991037 posted

    Thanks for the tip, but once again, no luck...this is the stack trace if this helps

     
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    

    200 records work fine, and i could show the fiddler request and responses on the succesful ones if that might help?

    Monday, August 26, 2013 8:44 AM
  • User-488622176 posted

    Probably not my best suggestion ever, but as this appears to be a pain in the a$$:

    I'd like to exclude the fact the error is at the client binding side (the ValidateRequestReplyResponse is a little dubious) or in the response of the answer from the server itself. Can you alter your service to make it NOT return any value (void), and make the operationcontract for the method OneWay (http://msdn.microsoft.com/en-us/library/ms733035.aspx)

    Recompile & redeploy, then please post us the error (if any)

    Monday, August 26, 2013 10:09 AM
  • User-1098991037 posted

    Thanks for your suggestion, I tried the above and i still get the same error message with the same exception details... is this pointing to the client config being the issue? (note that i have several other methods in my wcf which i havent made one-way - I dont think that would be an issue though as I can do multiple configurations and im NOT calling any of the other methods during my testing)

    Monday, August 26, 2013 8:14 PM
  • User-488622176 posted

    I think this excludes the error in is in the client binding (Rion, correct me if I'm wrong). As in this mode, you only launch data to your service, without expecting anything back.

    Did you try to put a try-cath around your service handling code to exclude internal data processing errors?

    Tuesday, August 27, 2013 3:08 AM
  • User-1098991037 posted

    Yes,I have got try catch in there, the method call is not even reached because what I did was startup the service through vs debug mode, added debug break points in it, changed the client config and tried to see where it might be going wrong but the break points/method never got hit/called.

    So so strange huh!! 

    Tuesday, August 27, 2013 3:42 AM
  • User-1098991037 posted

    finally!!

    It was because there was a ‘name’ value in the binding,. Therefore the custom values we were setting weren’t being applied and it was loading the server defaults (not even sure where the ‘defaults’ for the different bindings are kept!)  I found this out by an article I read online and making a new service using basic binding only..which kept failing,until I removed the name then it started working! Then I had to figure out how to do it for wsHttpBinding because with that binding, if you don’t specify the name (and then obviously you cant reference the configuration) you get all sorts or security issues etc and the service doesn’t work..so the solution was to add another binding without the name property in it.

    The settings were only needed on the server side in the end,because i left the default client values (lower than the ones in the example above) and it still worked. Below is the full web.config..note how i had to default for both basicHttpbinding and wsHttpbinding

    <bindings>
          <wsHttpBinding >
            <binding ***name="problemWithValue"***    maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <security mode="None">
                <transport clientCredentialType="None" />
                <message establishSecurityContext="false" />
              </security>
              <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
              <readerQuotas maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647" />
            </binding>
            <binding     maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <security mode="None">
                <transport clientCredentialType="None" />
                <message establishSecurityContext="false" />
              </security>
              <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
              <readerQuotas maxDepth="2147483647"
                             maxStringContentLength="2147483647"
                             maxArrayLength="2147483647"
                             maxBytesPerRead="2147483647"
                             maxNameTableCharCount="2147483647" />
            </binding>
          </wsHttpBinding>
          <mexHttpBinding>
            <binding name="higherMessageSize_MEX"  />                  
          </mexHttpBinding>
            <basicHttpBinding >
            <binding  maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
              <readerQuotas maxStringContentLength="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 3, 2013 7:49 PM