Tag Archives: asp.net

WCF RIA gzip compression of response

I was trying to enable gzip compression of my WCF RIA traffic to decrease the amount of data that is send between the client and server and improve performance.

Note: I used Fiddler2 to determine if the responses were actually compressed or not.

There is a lot of Q&A about this topic on the web, but nobody had a straight solution for me. Some posts refered to old versions of IIS or used 3rd party modules.

I was looking for a solution that will work from with IIS7.5 without installing any 3rd party modules.

Here is how I made it work.

Lets first install the necessary modules: the Dynamic and Static Content Compression modules:

How-to enable GZIP compression for normal traffic:
On Windows 7:
“Start->Control Panel->Programs and features” and click on “Turn Windows features on or off”.
Then enable:
“Dynamic Content Compression” and “Static Content Compression” in “Internet Information Services->World Wide Webservices->Performance Features” and press “Ok”.

Now your ‘normal’ HTTP responses are automatically compressed, but your WCF RIA traffic is not.

To enable this we will need to add the mime-type of our WCF RIA traffic to the list of mime-types that need to be compressed. On my system the mime-type for my WCF RIA traffic is application/msbin1. I assume this is the same for everybody.

How-to enable GZIP compression for WCF RIA Services traffic:
Open a command box (cmd.exe)
Navigate to C:\Windows\system32\Inetsrv\ and execute the following command to add the application/msbin1 mime-type to the list of types that needs to be compressed:

appcmd.exe set config -section:system.webServer/httpCompression /+”dynamicTypes.[mimeType=’application/msbin1′,enabled=’True’]” /commit:apphost

This will add an entry into the Windows\System32\Inetsrv\Config\applicationHost.config file.

Now restart your IIS server and compression is enabled for the WCF RIA Services.

Before:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 583
Content-Type: application/msbin1
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 11 Aug 2011 17:47:10 GMT

After:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/msbin1
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 11 Aug 2011 17:48:01 GMT
Content-Length: 336

I hope this post was helpful!

Useful link: http://www.iis.net/ConfigReference/system.webServer/httpCompression

Tips & Tricks: Extending your Entity Framework classes

There are different reasons why you would like to extend the existing properties on your entity framework classes, for instance when you want to add data validation attributes or the display attribute, commonly used in ASP.Net MVC to set the ‘display’ name of the property.

Here is how to do it without editing your auto generated Entity Framework (.edmx) file. ‘author’ is the entity framework class.

    [MetadataType(typeof(authorMetadata))]
    public partial class author
    {
    }

    public class authorMetadata
    {
        [Display(Name = "First name")]
        public string firstname { get; set; }
    }

We further extend the original author class by adding another partial class and specify which class contains the metadata for the class using the Metadatatype attribute.

Tips & Tricks: Accessing MembershipProvider from Silverlight

As you might noticed in the previous post, i’m working on a implementation of a custom MembershipProvider.

Well here is another useful link that shows how you can easily expose the AuthenticationService for your Silverlight application as a WCF Service:

Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight

I will probably have some other posts coming up about using the MembershipProvider in Silverlight and ASP.Net, so keep an eye out.

Tips & Tricks: Debug custom MembershipProvider

Problems with debugging your custom MembershipProvider when trying to access it through the “ASP.Net Web Application Administration” website?

Here is how to do it:

In VS2010, goto “Debug”->”Attach to process” and select WebDev.WebServer40.exe from the list, click “Attach”. Now your debugger is attached to the ASP.NET WAA website. Be patient, the loading of the necessary debug symbols can take some time while accessing the webpage.

Also make sure that you do a clean rebuild if your membershipprovider is part of a different assembly so the ASP.NET WAA website is using the latest version of your build.