Handling Large Data with SharePoint 2010 Custom WCF Service

October 16, 2014

Calling your custom WCF web service successfully with a small, known and fixed amount of test data only to have it fail with large and variable real world data? You can follow these steps to try and track down the issue. However, if you continue to get a 400 Bad Request error, you might be exceeding the maximum message size quota. The solution is to increase this limit as follows:

SPWebService contentService = SPWebService.ContentService;
SPWcfServiceSettings wcfServiceSettings = new SPWcfServiceSettings();
wcfServiceSettings.ReaderQuotasMaxStringContentLength = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxArrayLength = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxBytesPerRead = Int32.MaxValue;
wcfServiceSettings.MaxReceivedMessageSize = Int32.MaxValue;
wcfServiceSettings.MaxBufferSize = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxDepth = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxNameTableCharCount = Int32.MaxValue;
wcfServiceSettings.ReceiveTimeout = TimeSpan.MaxValue;

contentService.WcfServiceSettings["your_custom_service.svc"] = wcfServiceSettings;

A New Vector Toy for Designers

October 9, 2014

Adobe Illustrator has a formidable new opponent – meet Affinity Designer by Serif!

Serif specializes in creating software as an alternative to high end design programs. If you’re hesitant to pay a fortune for design software, whether you’re a professional, a student or simply trying vector illustration for the first time, Affinity Designer could be a great option for you.

The majority of the work I do is using Adobe Illustrator. It’s an amazing program and in my years of using it I haven’t found a vector tool that can rival it. So when a program claims to be “the fastest, smoothest, most precise vector graphic design software available,” it’s intriguing to say the least.

That’s a tall claim, so what are some of the fantastic features of this new software and how does it compare to Illustrator?

“Affinity Designer is so efficient it can open Adobe Photoshop PSDs faster than Adobe Photoshop”

Aside from all the standard tools and features offered by other vector software, here are a few extras that are the icing on the Affinity cake.

Speedy Gonzales

Affinity Designer is touted as an incredibly fast program, no matter the size of your illustration. It pans and zooms at 60fps! And speaking of zoom, one of the problems of Illustrator that I found is that the zoom is really limited. So I’m looking forward to trying out the 1,000,000% Zoom of Affinity.

Relax and Make Mistakes

I have a sticky note that says “Don’t Forget to Save” next to my shut down button. I can remove it because I know that AutoSave on Affinity will have my back.

You can go back over 8000 steps. I’m not saying you’ll make that many mistakes, but if you do you have the ability to go back.

Plays Well with Others

One of my concerns about switching to new vector software was compatibility with all my previous Illustrator files. Affinity Designer provides seamless transition between Illustrator and other design programs. It lets you import whole files or just elements from Illustrator or Photoshop.

• Affinity Designer supports custom toolbars, multiple screens, and custom panel layouts. And has great usability with trackpads, magic mice, keys, tablets, rights-clicks and mousewheels.

• Share straight to email, social media and iCloud.

• Supports multiple document types, from tiny designs to giant billboards to UI designs.

These are just a few of the numerous features available from this new software.

Affinity Designer has no subscription charges and is designed for designers of every level. You buy it exclusively from the Mac App Store and get free updates as they come in. As a lifetime PC user it makes me consider getting a Mac to try Affinity for myself.

Affinity 2

Paging with SharePoint Lists

October 2, 2014

Let’s say you have a SharePoint web part that displays data from a SharePoint list and you are running into performance issues, as you are simply attempting to display too much information.

One way to resolve this would be to apply paging. Paging is a technique where you only retrieve a chunk of the data instead of all the data which can improve performance.

Two key properties in paging are the page size and the page position (the current page).

In order to apply paging you will need to modify how you are currently retrieving the data. Assuming that you are retrieving all the data from the list, your code might look something like this:

SPQuery query = new SPQuery();

query.Query = string.Format("<Where><Eq><FieldRef Name='AccountID' /><Value Type='Text'>{0}</Value></Eq></Where>", accountID);

SPListItemCollection items = list.GetItems(query);

We will need to update the query object to set the page size, to do that just set the RowLimit property on SPQuery.

query.RowLimit = 5;

Next, you will need to set the page position. You can do this by setting the ListItemCollection.PagingInfo property on SPQuery. For the initial retrieve we don’t need to set this, but you will need to set it for retrieving the next page. SharePoint will actually give you the PagingInfo you need to retrieve the next page once we’ve executed the query.

SPListItemCollection items = list.GetItems(query);

var nextPageInfo = items.ListItemCollectionPosition.PagingInfo; // contains the PagingInfo needed to go to the next page

The returned PagingInfo is just a string that will look something like this: “Paged=TRUE&p_ID=5” this is what you will need to retrieve the next page of items.

The “p_ID=5” is telling SharePoint that it needs to retrieve the 5 (or whatever your page size is) items that come after the item with an ID of 5.

Now to retrieve the next page you will need to set the PagingInfo property on SPQuery.

query.ListItemCollectionPosition = new SPListItemCollectionPosition(nextPagingInfo);

To go to the previous page you will need to do some extra work, unfortunately SharePoint is not nice enough to give us the PagingInfo needed to go to the previous page.

Here is a simple way to get the PagingInfo for the previous page.

var prevPageInfo = string.Format("PagePrev=True&amp;Paged=TRUE&amp;p_ID={0}", items[0].ID);

The generated string will look something like this “PagePrev=True&Paged=TRUE&p_ID=6”, this is telling SharePoint that it needs to retrieve the 5 (or whatever your page size is) items that come before the item with an ID of 6.

Here’s a little illustration:

Paging with SharePoint lists

This is just the basics of paging with SharePoint lists, if you decide to apply sorting or filtering you will also need to take those into consideration as well.