locked
Enabling HTTP Compression in IIS Express for WCF Service RRS feed

  • Question

  • User806404777 posted

    I am using Visual Studio 2012 running on Windows 8. I have a WCF Service hosted in IIS Express for which the default page is MyService.svc and I have a client app which makes an HTTP Get request to that URI. The client sets the Accept header on the request to "application/json;odata=verbose" and my service duly returns a big block of JSON to my client.

    But now I want to test HTTP compression, so on the client, I now set the AcceptEncoding header to "gzip,deflate".

    In [MyDocuments]\IISExpress\config\applicationhost.config, I have added "application/json" into the <dynamicTypes> inside <httpCompression...> section:

            <httpCompression directory="%TEMP%\iisexpress\IIS Temporary Compressed Files">
                <scheme name="gzip" dll="%IIS_BIN%\gzip.dll" />
                <dynamicTypes>
                    <add mimeType="text/*" enabled="true" />
                    <add mimeType="message/*" enabled="true" />
                    <add mimeType="application/x-javascript" enabled="true" />
                    <add mimeType="application/atom+xml" enabled="true" />
                    <add mimeType="application/json" enabled="true" />
                    <add mimeType="*/*" enabled="false" />
                </dynamicTypes>
                <staticTypes>
                    <add mimeType="text/*" enabled="true" />
                    <add mimeType="message/*" enabled="true" />
                    <add mimeType="application/x-javascript" enabled="true" />
                    <add mimeType="application/atom+xml" enabled="true" />
                    <add mimeType="application/xaml+xml" enabled="true" />
                    <add mimeType="application/json" enabled="true" />
                    <add mimeType="*/*" enabled="false" />
                </staticTypes>
            </httpCompression>

    When I test this, I see the following in the tracelog:

    153. DYNAMIC_COMPRESSION_START 20:20:26.715
    154. DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="NO_MATCHING_SCHEME" 20:20:26.715
    155. DYNAMIC_COMPRESSION_END 20:20:26.715

    From what reading I've done, I could only find advice for 'big' IIS which suggests that IIS 8 only compresses certain file extensions: "compress(es) htm, html, and txt for STATIC compression, and asp, dll, and exe for DYNAMIC compression". Looks to me like IIS Express will not compress my ".svc" .

     Is that it - is it the .svc file extension that is the problem. If it is, how do I persuade IIS Express to compress the output from my WCF Service?

    Monday, September 3, 2012 4:45 PM

Answers

  • User-76669496 posted

    Hi,

    Try these commands:

    appcmd set config -section:urlCompression /doDynamicCompression:true

    appcmd set config /section:staticContent /+[fileExtension='.json', mimeType='application/json']

    appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost

    Be sure to restart IIS afterwards. Scott Hanselman has a nice walk through on this:

    http://www.hanselman.com/blog/EnablingDynamicCompressionGzipDeflateForWCFDataFeedsODataAndOtherCustomServicesInIIS7.aspx

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, September 4, 2012 1:57 PM
  • User-176674611 posted

    To use appcmd the for iis express, you will need to navigate to IIS express installation folder and use the appcmd.exe located there. The default installation path is "%programfiles%\iis express%".

    Thanks.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, September 5, 2012 11:12 PM

All replies

  • User-76669496 posted

    Hi,

    Try these commands:

    appcmd set config -section:urlCompression /doDynamicCompression:true

    appcmd set config /section:staticContent /+[fileExtension='.json', mimeType='application/json']

    appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost

    Be sure to restart IIS afterwards. Scott Hanselman has a nice walk through on this:

    http://www.hanselman.com/blog/EnablingDynamicCompressionGzipDeflateForWCFDataFeedsODataAndOtherCustomServicesInIIS7.aspx

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, September 4, 2012 1:57 PM
  • User806404777 posted
    Isn't this for 'big' IIS? Will this work also for IIS Express?
    Tuesday, September 4, 2012 5:40 PM
  • User-176674611 posted

    To use appcmd the for iis express, you will need to navigate to IIS express installation folder and use the appcmd.exe located there. The default installation path is "%programfiles%\iis express%".

    Thanks.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, September 5, 2012 11:12 PM
  • User806404777 posted

    Thanks - found appcmd.exe, and tried the commands you suggested. Threw errors though:

    C:\Windows\system32>cd "c:\Program Files\IIS Express"

    c:\Program Files\IIS Express>appcmd set config -section:urlCompression /doDynamicCompression:true
    Applied configuration changes to section "system.webServer/urlCompression" for "
    MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

    c:\Program Files\IIS Express>appcmd set config /section:staticContent /+[fileExtension='.json', mimeType='application/json']
    ERROR ( message:Cannot find SITE object with identifier "mimeType='application/json']". )

    c:\Program Files\IIS Express>appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost
    ERROR ( message:New add object missing required attributes. Cannot add duplicate
     collection entry of type 'add' with unique key attribute 'mimeType' set to 'app
    lication/json'
    . )

     

    What do I need to change?

    Monday, September 10, 2012 3:32 PM
  • User-176674611 posted

    The error indicates the entry for mimetype 'application/json' already exist, So what done exactly is enable dynamic compression for IIS express. If you restart iis express, does the issue persist? <STRIKE>If the issue persists, I would suggest you enable failed request tracing for further troubleshooting. You can add tracing rule like following to system.Webserver section of your web.config:</STRIKE>

    <STRIKE><tracing><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>  <traceFailedRequests><o:p></o:p>    <add path="*.json"><o:p></o:p>      <traceAreas><o:p></o:p>        <add provider="WWW Server" areas="Compression" verbosity="Verbose" /><o:p></o:p>      </traceAreas><o:p></o:p>      <failureDefinitions timeTaken="00:00:00" statusCodes="200-900" /><o:p></o:p>    </add><o:p></o:p>  </traceFailedRequests><o:p></o:p></tracing><o:p></o:p> </STRIKE>

    <STRIKE>And you can use the following command  to enable tracing and configure tracing log location for your site:</STRIKE>

    <STRIKE>appcmd.exe set config  -section:system.applicationHost/sites /"[name='Your Site Name']".traceFailedRequestsLogging.enabled:"True" /"[name='Your Site Name']".traceFailedRequestsLogging.directory:"Tracing Log Location"  /commit:apphost</STRIKE>

    <STRIKE>Replace the bold part of above command with site name and log location for your real scenario. The tracing logs should provide the root cause for the compression failure.</STRIKE>

    Thanks.

     Edit: Sorry for forgetting you've checked tracing already. Please check if a restart for iis express helps.

    Thursday, September 13, 2012 3:17 AM