CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

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

rated by 0 users
Answered (Verified) This post has 1 verified answer | 8 Replies | 0 Followers

Top 100 Contributor
68 Posts
superkuton posted on Sat, May 26 2012 9:43 AM

(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.

Answered (Verified) Verified Answer

Top 10 Contributor
1,772 Posts
Verified by superkuton

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>

Jonny Bekkum, Norway CslaContrib Coordinator

All Replies

Top 10 Contributor
1,772 Posts
Suggested by JonnyBee

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

Jonny Bekkum, Norway CslaContrib Coordinator

Top 100 Contributor
68 Posts

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?

 

Top 10 Contributor
1,772 Posts

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.

Jonny Bekkum, Norway CslaContrib Coordinator

Top 100 Contributor
68 Posts

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>

 

Top 10 Contributor
1,772 Posts
JonnyBee replied on Tue, May 29 2012 12:47 AM

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.

Jonny Bekkum, Norway CslaContrib Coordinator

Top 100 Contributor
68 Posts

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.

Top 10 Contributor
1,772 Posts
Verified by superkuton

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>

Jonny Bekkum, Norway CslaContrib Coordinator

Top 100 Contributor
68 Posts

Yes, that did it JonnyBee!

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

Thanks a lot, really!

 

Page 1 of 1 (9 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems