Leon Havin
Leon Havin

Reputation: 187

WCF: Server responding with Bad Request (400)

My WCF client works OK with WCF server except when making a call to the server trying to pass array of custom objects. When the array is 100 items it works fine, but when number of items is 300 the server throws exception Bad Request (400). So I assume that the key to the solution is in configuration files.

First of all here is the app.config for the client. The WCF client resides in a DLL which is Outlook Add-In. I copy this app.config to Outlook.exe.config to Outlook installation dir - something that is required for the Add-In to be loaded by Outlook:

<configuration>
  <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IJabberSvc" closeTimeout="00:01:00"           openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <security mode="Message">
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:9047/switchvox/alerter" binding="wsDualHttpBinding"
                bindingConfiguration="WSDualHttpBinding_IJabberSvc" contract="JabberService.IJabberSvc"
                name="WSDualHttpBinding_IJabberSvc">   
            </endpoint>
        </client>
    </system.serviceModel>
  <system.diagnostics>
    <trace autoflush="true" />
    <sharedListeners>
      <add name="sharedListener"
      type="System.Diagnostics.XmlWriterTraceListener"  initializeData="%AppData%\Mfg\ProjectName\Logs\SwitchvoxDialerTraceLog.svclog" />
    </sharedListeners>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sharedListener"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
        <listeners>
          <add name="sharedListener" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

  <userSettings>
    <SwitchvoxDialer.Properties.Settings>
      <setting name="InstallSubFolder" serializeAs="String">
        <value>Mfg\\ProjectName</value>
      </setting>
      <setting name="DialerTitle" serializeAs="String">
        <value>ProjectName</value>
      </setting>
    </SwitchvoxDialer.Properties.Settings>
  </userSettings>
</configuration>

The relevant part of the server config looks like this:

  <system.serviceModel>
    <services>
      <service name="WcfServiceLib.JabberSvc" behaviorConfiguration="JabberSvc">
        <endpoint address="http://localhost:9047/switchvox/alerter"      binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IJabberSvc" contract="WcfServiceLib.IJabberSvc" name="WSDualHttpBinding_IJabberSvc">
          <identity>

        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9047/switchvox/alerter"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="JabberSvc">
          <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483646" />
          <serviceTimeouts transactionTimeout="00:10:00" />
          <!-- 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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IJabberSvc" closeTimeout="00:01:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                 bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                 messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647"
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00"/>
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <!-- Enable message tracing by adding this section - Remove for production code -->
    <diagnostics>
      <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true"
      logMessagesAtTransportLevel="true"
      maxMessagesToLog="100000" />
    </diagnostics>

  </system.serviceModel>

The app.config produces ServerName.exe.config that in bin/Debug (previously I had it as embedded resource but it did not help either...

As you can see I increased all the numbers for buffers, messages, etc. to maximum and made sure that the time values are high enough... I am convinced that that the problem is that somehow either the server or the client do not know about these increased values, but cant figure out why...

Upvotes: 1

Views: 1554

Answers (2)

muruge
muruge

Reputation: 4133

WCF does not return/show lot of information about what's actually wrong in its side (sad). Try configuring WCF Tracing and see if it helps.

Upvotes: 1

Ann B. G.
Ann B. G.

Reputation: 302

Try message encoding with MTOM. See the following links for more info:

http://msdn.microsoft.com/en-us/library/ms733742.aspx and http://msdn.microsoft.com/en-us/library/aa395209.aspx

If that doesn't work, use Fiddler to get more information on the error. A 400-bad request can mean a lot of things.

Upvotes: 1

Related Questions