LavaBlast Software Blog

Help your franchise business get to the next level.
AddThis Feed Button

Gotcha: gzip compression in SOAP message calls

clock August 20, 2009 10:30 by author JKealey

Some of our software systems here at LavaBlast exchange “large” data sets (only a few megabytes) in order to synchronize data between the systems. The data being exchanged is simple XML and we assumed that the SOAP calls were compressed by the built-in HTTP compression in the web server. However, checking the HTTP headers on the server when a call was made, we noticed that the Accept-Encoding header was missing. (HttpContext.Current.Request.Headers["Accept-Encoding"] did not exist).

Surprised, we turn to Google and immediately found a reference to the EnableDecompression property of the SOAP client. By setting it to true, we ensured our SOAP client was requesting gzip compression when making calls.

LavaBlastServer.Inventory centralServer = new LavaBlastServer.Inventory();
centralServer.EnableDecompression = true;

There is not much more to it. However, if you’re unaware that this setting is required, you may have clients running in the wild that don’t use gzip compression but could benefit from it.

kick it on

Gotcha: ASP.NET and exceptions in asynchronous tasks

clock October 30, 2008 13:00 by author JKealey

Awesomeness Here's a little piece of information you might not know about how ASP.NET 2.0 and above operate. Simply put, if an unhandled exception occurs in a secondary thread which has been launched by your ASP.NET application, IIS will force your application to restart. This can mean lost sessions, bad server side state, slow reloads and, in general, is a bad thing. However, these kinds of exceptions are a pain to discover and resolve if you don't know what you're looking for because the built-in ASP.NET error handler does not get fired and your user is not redirected to an error page, unless something breaks after the web server restarts. (This article explains the cryptic messages you will see in the Event Log).

Here's a simple scenario based on the integration between our interactive kiosk created for The Code Factory co-working space and Twitter. We want our web application to post messages on Twitter when certain events occur (member check-in and member check out). Because we did not want to re-invent the wheel, we found a Twitter C# Library with a permissive software license. Noticing that posting to Twitter slowed down our application and because we didn't want our application to depend on Twitter's availability, we decided to run this code asynchronously. Being careless, we supposed that should anything bad occur in this second thread (timeouts, invalid login/password, etc.), the system will simply not be able to post, which was not a problem for us. We were wrong, and the whole web application restarted because of this. (This was not the case in ASP.NET 1.x and was previously discussed by others).

In any case, here's some sample code to run the Twitter library asynchronously, including a try/catch.

using System;
using System.Collections.Generic;
using System.Text;
namespace LavaBlast.Util.Twitter
    public class AsyncTwitter
        public void Update(string userName, string password, string status)
            TwitterDelegate caller = new TwitterDelegate(UpdateTwitter);
            caller.BeginInvoke(userName, password, status, new AsyncCallback(CallbackMethod), caller);
        protected delegate void TwitterDelegate(string userName, string password, string status);
        protected static void CallbackMethod(IAsyncResult ar)
            TwitterDelegate caller = (TwitterDelegate)ar.AsyncState;
        protected static void UpdateTwitter(string userName, string password, string status)
                Twitter t = new Twitter();
                t.Update(userName, password, status, Twitter.OutputFormatType.XML);
            catch (Exception ex)
                LavaBlast.ElectronicJournal.Error("Unable to post to twitter.", ex);
                // ignore. 

The lesson learned is unhandled exceptions in other threads can wreak havoc on your ASP.NET application. To help debug these kinds of errors when they occur, I do suggest you setup the HttpModule developed by Peter A. Bromberg that adds the actual exception in your Event Log. Peter describes the problem in more detail than I do, and is worth a read.

Have a Happy Halloween! (Halloween will be weird for us in 2008 because we were hit by the year's first snowstorm on Tuesday.)


kick it on

Gotcha: WebKit (Safari 3 and Google Chrome) Bug with ASP.NET AJAX

clock October 20, 2008 23:38 by author JKealey

image Tonight we fixed a severe compatibility issue that I feel you should all be aware of.

Executive summary: ASP.NET AJAX breaks down completely in some circumstances when using WebKit-based browsers. Reference the JavaScript provided below to solve these problems.

As you know, we develop web applications using ASP.NET AJAX and tonight we were notified that one of our users was not able to proceed to the payment page on one of our e-commerce websites. (As you can imagine, preventing payment is the worst thing that can happen in an e-commerce site!). After some investigation, we discovered the user was using Safari 3 on an Intel-based MacBook Pro just like the one I recently purchased. I picked up my MBP and re-tested the site, going through exactly the same steps this user did (thanks to the auditing capabilities we've built into the e-commerce engine). The site works fine in general, except at one particular page deep within the bowels of the website, when clicking on a button, the ASP.NET UpdateProgress control would show and never go away during the asynchronous postback.

I first thought this was an SSL issue such as the evil IE White Screen Bug, but I managed to replicate on my local machine without using SSL. This button is contained inside a dozen layers of user controls. Fortunately, I use this user control in another location. I tested one of these locations (where it isn't as nested) and this one worked. I then proceeded to hide my user controls, layer by layer and narrowed the issue to ASP.NET validators on one of my pages.

<asp:RequiredFieldValidator ID="rfvName" runat="server" ErrorMessage="Required"
    Display="Dynamic" ControlToValidate="txtName"="true" />

Adding Visible="false" to this (and the other validators) on my user control unfroze the UpdateProgress. My first thought was that I must have reached a limit in identifier name lengths because my validator was nested very deeply. I proceeded to rename a few layers to make the name shorter. This changed nothing. I then discovered how to enable a FireBug-like tool in Safari called Web Inspector. This helped me discover an obscure JavaScript error.

Sys.ScriptLoadFailedException: The script 'http://localhost:2241/ScriptResource.axd?[...]' failed to load.

After changing from ScriptMode="Release" to ScriptMode="Debug", I got additional details.

Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().

This finally lead me to an old post on the ASP.NET forums. It appears that Safari 2 needed a few hacks in the ASP.NET AJAX JavaScript code to work properly. These hacks are no longer needed in Safari 3 (or Google Chrome) because WebKit works out of the box. However, these hacks sometimes broke WebKit-based browsers as I discovered today. The first solution in the forums is to change the JavaScript files used by the framework but we didn't like that solution very much. The second comment provided a solution which we found reasonable. 


The workaround simply tells ASP.NET AJAX that Safari 3 and Google Chrome are a new type of browser instead of the old Safari for which workarounds had to be programmed.

1) Create a new file called webkit.js

Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if( navigator.userAgent.indexOf( 'WebKit/' ) > -1 )
  Sys.Browser.agent = Sys.Browser.WebKit;
  Sys.Browser.version = parseFloat( navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]); = 'WebKit';

2) Reference this webkit.js from your ScriptManager

<ajax:ToolkitScriptManager ID="scripts" runat="server" ScriptMode="Release" EnableHistory="true" 
EnableSecureHistoryState="false" EnablePageMethods="True" CombineScripts="true" 
OnAsyncPostBackError="Page_OnAsyncError" OnNavigate="OnHistoryNavigate">
        <asp:ScriptReference Path="~/js/webkit.js" />

We hope this will help some of you!

kick it on

VS.NET 2008 IDE Frozen After Compilation

clock January 16, 2008 21:08 by author JKealey

Each and every time I've compiled my solution over the last month, I've had to wait approximately 30 seconds for the IDE to resume after compiling. It simply said Build failed / Build succeeded and would not let me click anywhere in the UI for a painful half-minute (which I put to good use).

At first, I assumed this was another "feature" of VS.NET that was causing me pain and suffering, just like when my VS.NET 2005 decided to make me pay for cheating on it with another IDE (Eclipse) when I was working on a few open source Java projects using Eclipse (StatSVN and jUCMNav).

Evil VS.NET 2005

I decided to launch VS.NET 2008 in Safe Mode to verify if this would fix my problem and, to my surprise, it did. I probably have an evil add-in that was migrated from VS.NET 2005... to be investigated.

Update: Even in safe mode, it started doing it again after a couple hours of work. I'll file this into the "unexplained" category, alongside my mysterious "clipboard doesn't work for large images when memory usage is too high". From what I can see, Windows 32bit with the /PAE or /3GB options simply doesn't work. I need to upgrade to a 64bit OS to use my 4GB ram because the startup options aren't working well for me.

Using { and } in string.Format

clock January 16, 2008 14:02 by author EtienneT

Have you ever tried to use the { and } characters in the c# string.Format() method?  If you have, then you probably ran into a problem.  I'm posting this because this little Gotcha might not turn up until much later if your string formats are dynamically loaded from some external source, such as RESX files.

In any case, I sometimes find it useful to write some JavaScript code directly in C# and then dynamically insert it into the page with the ScriptManager.  Here is a quick example:

Basically, I write my JavaScript code on multiple lines with the @"" notation.  Then, I have to escape all { and } characters using {{ or }} otherwise string.Format will run into a System.FormatException: Input string was not in a correct format exception.  I can customize my JavaScript (or insert control.ClientID parameters) this way while retaining a readable format in the C# code.

Month List


The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign in