(Server Error 400 Bad Request) Configuration for wcf client (windows forms)?

(Server Error 400 Bad Request) Configuration for wcf client (windows forms)?

Old forum URL: forums.lhotka.net/forums/t/11375.aspx


superkuton posted on Saturday, May 26, 2012

(From a background of CSLA 3.8 using windows forms, I am now upgrading an application using CSLA 4.3 in silverlight and windows forms using WCF.)

My sample editable child collection can handle inserts and updates in both SL and Windows forms.

However, i have encountered a problem in the windows forms. After inserting a certain number of child objects, I encounter the (400) Bad request error.

I just wonder if there is a configuration required in the windows app.config file to solve this.

 

 

--------------------------------------------------------------------------------------------------------------------------

Thank you to Rocky for the great framework and the great CSLA community for the support.

JonnyBee replied on Sunday, May 27, 2012

Hi,

Is the error only occuring in the WinForms client or both?

You may have to increase the MaxBufferSize/MaxReceiveMessagesize and make sure thay are the same on sever and client.

Read more in the CSLA FAQ: http://www.lhotka.net/cslanet/faq/DataPortalFaq.ashx

superkuton replied on Sunday, May 27, 2012

Hello JonnyBee,

It is occurring only in the WinForms client.

Does increasing the MaxBufferSize/MaxReceiveMessagesize mean changing my app.config (WinForm client) to include the settings for the wsHttpBinding?

I am just new to WCF, pardon me, but does this have to do with the compression in SL but none in WinForm?

 

JonnyBee replied on Monday, May 28, 2012

It has to with WCF default limits inbound/outbound message to maximum size of 64K.

If a message arrives with larger content you 400 : Bad Message exception.

Yes, it means that you should try and change tha app config on your WinForm client - as per the instrictions in the FAQ.

superkuton replied on Monday, May 28, 2012

thanks JonnyBee.

I tried but the error still exists, only in the WinForms.

I have the following configs:

 

WCF web.config:

(in the system.servicemodel)

 <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_IWcfPortal"                
                 maxReceivedMessageSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 maxBufferSize="2147483647">
          <readerQuotas maxBytesPerRead="2147483647"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxDepth="2147483647"/>
        </binding>
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IWcfPortal"
                 maxReceivedMessageSize="2147483647">
          <readerQuotas maxBytesPerRead="2147483647"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxDepth="2147483647"/>
        </binding>
      </wsHttpBinding>
    </bindings>

 

WINFORM app.config:

(in full)

<?xml version="1.0"?>
<configuration>

 
  <appSettings>
    <add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>
    <add key="CslaDataPortalUrl" value="http://localhost:2645/WcfPortal.svc"/>
    <add key="CslaPropertyChangedMode" value="Windows"/>   
  </appSettings>
 
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IWcfPortal"
                 maxReceivedMessageSize="2147483647">
          <readerQuotas maxBytesPerRead="2147483647"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxDepth="2147483647"/>
        </binding>
      </wsHttpBinding>
    </bindings>   
  </system.serviceModel>

  <system.web>
    <httpRuntime maxRequestLength="2147483647" />
  </system.web>
 
</configuration>

 

JonnyBee replied on Tuesday, May 29, 2012

Hi,

superkuton
  <appSettings>
    <add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>
    <add key="CslaDataPortalUrl" value="http://localhost:2645/WcfPortal.svc"/>
    <add key="CslaPropertyChangedMode" value="Windows"/>   
  </appSettings>

The above settings should be sufficient as CSLA will auto-configure the rest. 

(from Csla.DataPortalClient.WcfPortal.cs)

    protected virtual ChannelFactory<IWcfPortal> GetChannelFactory()
    {
      // if dataportal url is specified use this with default wsHttBinding
      if (!string.IsNullOrEmpty(ApplicationContext.DataPortalUrlString))
      {
        var binding = new WSHttpBinding()
        { 
          MaxReceivedMessageSize = int.MaxValue, 
          ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas() 
          {
            MaxBytesPerRead = int.MaxValue,
            MaxDepth = int.MaxValue,
            MaxArrayLength = int.MaxValue,
            MaxStringContentLength = int.MaxValue,
            MaxNameTableCharCount = int.MaxValue
          }
        };
        return new ChannelFactory<IWcfPortal>(binding, new EndpointAddress(ApplicationContext.DataPortalUrl));
      }
 
      // else return a channelfactory that uses the endpoint configuration in app.config/web.config
      return new ChannelFactory<IWcfPortal>(_endPoint);
    }

You must be aware that declaring the bindings doesn't necessarily mean that CSLA or WCF will pick it up.

To dig deeper into the issue use Fiddler (http://www.fiddlertool.com) or a network package monitor to capture the messages and inspect how they are sent to the server and when the error happends.

superkuton replied on Tuesday, May 29, 2012

I changed the app.config to the original configuration without the additional settings on bindings, etc.

Tried to work with Fiddler, but I don't know how to use it, even after viewing their videos and poring over their documentation.

I think the error is not only on my application, but i checked on the PTracker sample and found out the same results.

In the winforms UI of the PTracker, in the RoleEdit winform, I can no longer add another role after the 8th record.

But in the SL UI, there's no problem.

I hope you can check more on this JonnyBee.

Thanks for the help, I am sorry I don't know how to use Fiddler.

JonnyBee replied on Tuesday, May 29, 2012

PTracker sample fails as the WCF server is not configured correctly.

The bindingConfiguration attribute is missing for .NET portal but is correct for Silverlight

Should be:

      <service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
        <endpoint contract="Csla.Server.Hosts.IWcfPortal" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IWcfPortal"/>
      </service>

    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IWcfPortal"
                 maxReceivedMessageSize="2147483647">
                    <readerQuotas maxBytesPerRead="2147483647"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"
                        maxNameTableCharCount="2147483647"
                        maxDepth="2147483647"/>
        </binding>
      </wsHttpBinding>
    </bindings>

superkuton replied on Tuesday, May 29, 2012

Yes, that did it JonnyBee!

Following the PTracker configurations, I also incorrectly configured my wcf.

Thanks a lot, really!

 

Copyright (c) Marimer LLC