WCF Rest on Azure not getting Http Compression for JSON data
-
2012년 4월 19일 목요일 오후 5:51
Hi,
I'm trying to get my WCF Rest service working with HTTP Compression and already made several changes to my project, but nothing works.
I've added the following items to my Web.config file:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <urlCompression doDynamicCompression="true" dynamicCompressionBeforeCache="true" doStaticCompression="true" /> <httpCompression cacheControlHeader="max-age=86400" noCompressionForHttp10="false" noCompressionForProxies="false" sendCacheHeaders="true" minFileSizeForComp="1"> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/x-javascript" enabled="true" /> <add mimeType="*/*" enabled="false" /> <add mimeType="application/json" enabled="true" /> <add mimeType="application/atom+xml; charset=iso-8859-1" enabled="true" /> <add mimeType="application/xml; charset=iso-8859-1" enabled="true" /> <add mimeType="application/xml; charset=utf-8" enabled="true" /> <add mimeType="application/json; charset=iso-8859-1" enabled="true" /> <add mimeType="application/json; charset=utf-8" enabled="true" /> <add mimeType="application/atom+xml; charset=utf-8" enabled="true" /> </dynamicTypes> </httpCompression> </system.webServer>I've created a EnableCompression.cmd file, set it to copy always and added the following commands to it:
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/urlCompression /doDynamicCompression:True /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/json',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/json',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/atom%%2bxml;charset=iso-8859-1',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/xml; charset=iso-8859-1',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/xml; charset=utf-8',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/json; charset=iso-8859-1',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='true'] /commit:apphost %windir%\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /+dynamicTypes.[mimeType='application/atom%%2bxml;charset=utf-8',enabled='true'] /commit:apphost
And added a startup key to ServiceDefinition.csdef file:
<Startup> <Task commandLine="EnableCompression.cmd" executionContext="elevated" taskType="simple" /> </Startup>
But nothing works.
Can you help me?
Here is the Request and Response Headers:
Response Headers Content-Length 135734 Content-Type application/json; charset=utf-8 Date Thu, 19 Apr 2012 17:00:45 GMT Server Microsoft-IIS/7.5 X-Powered-By ASP.NET Request Headers Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Connection keep-alive Host bbf1e5ef34174619a889ee7abbb52e97.cloudapp.net User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".
Se achou este post útil, por favor clique em "Votar como Útil". Se por um acaso respondeu sua dúvida, lembre de "Marcar como Resposta".
모든 응답
-
2012년 4월 20일 금요일 오전 8:13중재자
Hi,
Would you like to make sure that your startup task is executed in Azure VM? Do you have enable any Network Proxy?
From your situation, you mean "nothing works" and there's no exception message was thrown, try to use Azure Remote desktop to connect to Azure VM to see IIS configuration.
Hope this helps.
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
-
2012년 4월 22일 일요일 오후 8:23
Hi,
I changed a few things and now it works. First, I removed the settings from the web.config file and changed the EnableCompression.cmd to just this:
%windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost %windir%\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
I think that the fact that I've used both methods, web.config settings and startup task, must be the cause of the problem.If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".
Se achou este post útil, por favor clique em "Votar como Útil". Se por um acaso respondeu sua dúvida, lembre de "Marcar como Resposta".
- 답변으로 표시됨 Juliano Nunes Silva Oliveira 2012년 4월 22일 일요일 오후 8:23
-
2012년 8월 2일 목요일 오전 7:38
Actually, the reason that the .config file changes didn't work were because they were being made in the wrong file. The web.config file doesn't control <httpCompression>, the applicationHost.config does.
Also, loading a configuration file and issuing the same commands via appcmd wouldn't prevent the .config file from properly being applied. Depending on the commands issued, they might be deferred until an application pool, app domain, or IIS restart.
- 답변으로 제안됨 Sami Rageb 2012년 8월 2일 목요일 오전 7:39

