Home > English > WCF RIA Services – “The maximum uri length of 2083 was exceeded.”

WCF RIA Services – “The maximum uri length of 2083 was exceeded.”

I came across this exception the other day and thought it was weird enough to merit a post on it. In the enterprise system that I have designed I have the concept of a quick search and advanced search capabilities. You can see an example of quick search below:

When the user performs a quick search, the results are loaded into the Sidebar as well as into a DataPager for paging the data. Quick search is handled by allowing a user to enter in a ID or a business name. I handle this by creating two FilterDescriptors that operate against the properties that I want as shown below:

SearchFilterDescriptors.Add(new SearchFilterDescriptor("ID", FilterOperator.IsEqualTo, PropertyType.Integer));
SearchFilterDescriptors.Add(new SearchFilterDescriptor("Name", FilterOperator.StartsWith, PropertyType.String));

This works just fine in scenarios when I know exactly what I want to filter against but there are scenarios that I don’t know what the filter definition is going to be ahead of time. This is where the Advanced search screen comes into play:

With this screen, a user can select many properties that make up an “Account” record and then click the search button. A back-end process is created to find the set of records found and then I am dynamically creating FilterDescriptor objects. It was When I used a search criteria that brought back a lot of records that I received the following error:

Doing some research, I found this forum’s post as well as this blog entry discussing what I could do to fix this.

The interesting thing to note is that WCF RIA Services uses GET by default for all Query attributes. This explains why I was getting the exception due to the fact that I was building a query string that was larger than the maximum length.

It turns out that all I really needed to do was make a slight modification to my Query on the server as shown below:

public IQueryable<Organization> ReturnOrganization()
    return this.ObjectContext.Organization
        .OrderBy(x => x.OrganizationName);

By adding the HasSideEffects=true parameter WCF RIA Services uses Post instead of the default Get. Now we can have as complex a query as we want. This allowed me to have a dynamic advanced search screen and not worry about how many filters I was creating.

The way I accomplished this dynamically was by creating an instance of a FilterDescriptorCollection

var filter = new FilterDescriptorCollection();
foreach(var item in e.Value)
    var dto = item;
    filter.Add(new FilterDescriptor("ID", FilterOperator.IsEqualTo, dto.Value));

I use Prism’s EventAggregator to send an event so that the other screen can be notified of the Advanced Search Event. On the main screen, I have this code in place to apply the filter:

public void OnAdvancedSearchEvent(FilterDescriptorCollection filter)
    if (filter.Count > 0)
        View.DDS.FilterOperator = FilterDescriptorLogicalOperator.Or;
        foreach(var item in filter)
            var fd = item;

Another approach to this could be to handle the filter completely on the server and use a boolean parameter to indicate when to use the filter. Since my filter information was actually coming from the database I could have accomplished the same user experience but I would have never run into the this exception.

Hope this helps….

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: