Invoking custom WCF service from under Sharepoint 2010 throws an Impersonation error from SQL

I had a problem with one of my WCF services that was running under Sharepoint 2010. The problem was that when that service tries to access the database to add a record, i got the below exception.

System.Data.SqlClient.SqlException: A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 – Either a required impersonation level was not provided, or the provided impersonation level is invalid.)

It was very weird for me because my connection string was configured to use SQL authentication. So I do not understand why is it trying to impersonate.

Anyways, I have done a simple workaround to overcome that problem. I simply disabled the shared memory provider from the SQL configuration manager.


That way I forced it to work via named pipes. And it worked :). Still I do not know understand what was the problem originally, however, it worked.


List of Microsoft Installer (MSI) CustomActionData properties

I ran across a very useful list of all MSI CustomActionData properties on msdn:

CustomActionData Properties List

How to get the path where is the silverlight xap file is served

In case you are developing a silverlight application that contains images. You can set the build action of these images to Embedded Resource so as to have them within your XAP file and hence reference them relatively. However, in case you do not want to do so, you can still reference your images easily by setting their passes relative to the current path of the XAP file. The line of code below gets the current path of the running XAP file.


Escaping curly braces in XAML code

Sometimes you want your user interface text contains a curly brace “{“. Unfortunately, the xaml parser will consider it as markup extension and will refuse to compile. For example, the below code will not compile and will give an error: The given key was not present in the dictionary.

TextBlock Text="{Username:"

In order to escape the curly brace, you need to add “{}” before your text brace as shown below:

TextBlock Text="{}{Username:"

The extension name ‘enableWebScript’ is not registered error

While deploying a project I am working on that contain an AJAX enabled WCF service, I got the following error:

Invalid element in configuration. The extension name ‘enableWebScript’ is not registered in the collection at system.serviceModel/extensions/behaviorExtensions.

After hours of searching, it turned out to be that when you run the wcf uninstall command as shown below, it removes with the configurations from the machine.config.

servicemodelreg.exe -u

I found someone who suggested to add the xml tags manually to the machine.config. Although it worked, I got other errors. At the end, I reinstalled .Net FrameWork 3.5 SP1, in order to resolve that issue.

Measuring JavaScript performance on webpages

Most web pages nowadays contain big chunks of java scripts that help pages to be more appealing. However, java scripts affects web pages performance because browsers must execute code within all the script tags before rendering the page. That’s why the more script you have on your page, the more delay your page is gonna suffer before starting to render. That’s why one must make sure to use efficient scripts that does not affect the page performance. But how do you measure your script performance. Well, there are two ways to measure your java script function performance, whether manually or using a performance profiling tool. 

1- Manually testing your java script function performance involve one writing custom code to test how long his function takes to execute. This technique is really simple because all what you need to do is to add a line of code at the beginning of the function and another one at the end to calculate the time the function took to finish.

function myFunction()
var started = new Date().getMilliseconds();
//Your code Here
var ended = new Date().getMilliseconds();
Alret ("Function MyFunction executed in" + stop - start);

As you can see, what I have done is adding a statement to get the time at the beginning of the function and another one to get the time at the end of the function then subtract them to calculate how long did this function take.

2- The other way to measure the performance of your java script function is to use a performance profiler tool which would give you a complete picture of your page execution. The most famous tool is yslow which is an addons on firefox.

How to detect if the user is shutting down or logging off in WPF application?

Withing WPF application, you can detect if the user is shutting down or logging off and thereby take some action like saving for example your project. In order to do so, you will need to register to the Application SessionEnding event.

Application.Current.SessionEnding +=new SessionEndingCancelEventHandler(Current_SessionEnding);

You can then use the SessionEndingCancelEventArgs.ReasonSessionEnding to know exactly the reason of the session ending, whether it was because of a shuttdown or logoff.

private void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e)
  if (e.ReasonSessionEnding == ReasonSessionEnding.Logoff)
      MessageBox.Show("User Logged off the computer");
  else if (e.ReasonSessionEnding == ReasonSessionEnding.Shutdown)
      MessageBox.Show("User Shut down his machine");