Answered by:
Help needed: Gzip encoding problem with WCF service

Question
-
Hi All!
I have recently been through this post, and am totally stuck now:
http://social.msdn.microsoft.com/Forums/en-US/uklaunch2007ado.net/thread/c9dd4b76-5afa-42aa-a81d-35abd512e645
Basically, I have Sync Framework application, which used to work fine with a basic http binding service. But, with the amount of data being transferred I needed to implement gzip encoding (or some form of compression). I have it to a point where I can open the .svc file on the server, with no errors, but when I run the client application (after re-building the service reference), I get:
"Exception has been thrown by the target of an invocation."
The inner exception is:
{"The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'application/x-gzip'.."}
Ok, it kinda makes sense... but is it the service causing the issue? or the client? or both? And where do I tell it to use gzip encoding?
Client Endpoints:
<client> <endpoint address="http://webservices.abc123.com/ABCSalesForce3/MobileApp_SyncService.Service1.svc binding="customBinding" bindingConfiguration="endpointService1" contract="ServiceReference1.IService1" name="endpointService1" /> <endpoint address="http://webservices.abc123.com/ABCSalesForce3/MobileApp_SyncService.Service1.svc binding="customBinding" bindingConfiguration="endpointABC2DataSync" contract="ServiceReference1.IcacheABC2DataSyncContract" name="endpointABC2DataSync" /> </client>
Client Bindings:
<bindings> <customBinding> <binding name="gzipCustomBinding"> <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" /> <httpTransport manualAddressing="false" maxReceivedMessageSize="6553600" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" realm="" useDefaultWebProxy="true" /> </binding> <binding name="endpointService1"> <!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://tempuri.org/': --> <!-- <wsdl:binding name='endpointService1'> --> <!-- <gzip:GZipEncoding xmlns:gzip="http://schemas.microsoft.com/ws/06/2004/mspolicy/netgzip1">..</gzip:GZipEncoding> --> <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" writeEncoding="utf-8"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </textMessageEncoding> <httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" /> </binding> <binding name="endpointABC2DataSync"> <!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://tempuri.org/': --> <!-- <wsdl:binding name='endpointABC2DataSync'> --> <!-- <gzip:GZipEncoding xmlns:gzip="http://schemas.microsoft.com/ws/06/2004/mspolicy/netgzip1">..</gzip:GZipEncoding> --> <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" writeEncoding="utf-8"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </textMessageEncoding> <httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" /> </binding> </customBinding> </bindings>
<services> <service behaviorConfiguration="MobileApp_SyncService.Service1Behavior" name="MobileApp_SyncService.Service1"> <endpoint address="" binding="customBinding" bindingConfiguration="gzipCustomBinding" name="endpointService1" bindingName="gzipCustomBinding" contract="MobileApp_SyncService.IService1" /> <endpoint address="mex" binding="mexHttpBinding" name="endpointMex" contract="IMetadataExchange" /> <endpoint address="" binding="customBinding" bindingConfiguration="gzipCustomBinding" name="endpointABC2DataSync" contract="MobileApp_SyncService.IcacheABC2DataSyncContract" /> <host> <baseAddresses> <add baseAddress="http://localhost/Design_Time_Addresses/MobileApp_SyncService/Service1/" /> </baseAddresses> <timeouts closeTimeout="00:02:00" openTimeout="00:10:00" /> </host> </service> </services>
Service Bindings:
<bindings> <customBinding> <binding name="gzipCustomBinding"> <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" /> <httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="536870912" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="536870912" realm="" transferMode="Streamed" useDefaultWebProxy="true" /> </binding> </customBinding> </bindings>
Thanks in advance!! I would greatly appreciate any help you could give me.- Edited by Edgeman Wednesday, July 1, 2009 10:27 AM
Wednesday, July 1, 2009 5:51 AM
Answers
-
I love it when I am able to learn & answer my own questions.
The "System.OutOfMemoryException" when away when I moved from Buffered to StreamedResponse, which meant the buffer never got filled, hence no System.OutOfMemoryException (I am assuming this btw).
So, all good & happy now. I have the encoder up and running, and in my latest test I synchronised 250,000+ records in about 11 minutes. This took well over 30 minutes before, and a *LOT* more bandwidth :-)
- Marked as answer by Edgeman Thursday, July 2, 2009 10:30 PM
Thursday, July 2, 2009 10:30 PM
All replies
-
You should turn on tracing (http://msdn.microsoft.com/en-us/library/ms733025.aspx) on the client and server to find out more about the problem.
Nordine Ben BachirWednesday, July 1, 2009 2:31 PM -
Ok, I've never used tracing before, any pointers as to what I should be looking out for?Wednesday, July 1, 2009 8:31 PM
-
Part of the problem could be that you're service is trying to host two different endpoints at the same address. Your first and third endpoint listed in the Service Endpoints section are both hosted at the base address. I'm actually surprised your service even runs.
Don't forget to mark the best answer to your question!Wednesday, July 1, 2009 9:11 PM -
Thanks for the tip. I've completely re-done the sync WCF service and client. I am also now testing locally to count out any firewalls, etc between my dev machine and the server. Hhere are the bits now:
Client side:<system.serviceModel> <extensions> <bindingElementExtensions> <add name="gzipMessageEncoding" type="Microsoft.ServiceModel.Samples.GZipMessageEncodingElement, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </bindingElementExtensions> </extensions> <bindings> <customBinding> <binding name="gzipCustomBinding_IcacheABCMobileAppSyncContract"> <!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://tempuri.org/': --> <!-- <wsdl:binding name='gzipCustomBinding_IcacheABCMobileAppSyncContract'> --> <!-- <gzip:GZipEncoding xmlns:gzip="http://schemas.microsoft.com/ws/06/2004/mspolicy/netgzip1">..</gzip:GZipEncoding> --> <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" writeEncoding="utf-8"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </textMessageEncoding> <httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" /> </binding> </customBinding> </bindings> <client> <endpoint address="http://localhost:8327/cacheABCMobileAppSyncService/" binding="customBinding" bindingConfiguration="gzipCustomBinding_IcacheABCMobileAppSyncContract" contract="serviceABCMobileApp3.IcacheABCMobileAppSyncContract" name="gzipCustomBinding_IcacheABCMobileAppSyncContract" /> </client> </system.serviceModel>
Server Side:
<system.serviceModel> <bindings> <customBinding> <binding name="gzipCustomBinding"> <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" /> <httpTransport hostNameComparisonMode="StrongWildcard" manualAddressing="False" maxReceivedMessageSize="6553600" authenticationScheme="Anonymous" bypassProxyOnLocal="False" realm="" useDefaultWebProxy="True" /> </binding> </customBinding> </bindings> <extensions> <bindingElementExtensions> <add name="gzipMessageEncoding" type="Microsoft.ServiceModel.Samples.GZipMessageEncodingElement, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </bindingElementExtensions> </extensions> <services> <service name="ABCMobileApp3_SyncServer.cacheABCMobileAppSyncService" behaviorConfiguration="ABCMobileApp3_SyncServer.cacheABCMobileAppSyncServiceBehavior"> <host> <baseAddresses> <add baseAddress ="http://localhost:8327/cacheABCMobileAppSyncService/"/> </baseAddresses> </host> <endpoint address="" binding="customBinding" bindingConfiguration="gzipCustomBinding" bindingName="gzipCustomBinding" contract="ABCMobileApp3_SyncServer.IcacheABCMobileAppSyncContract"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ABCMobileApp3_SyncServer.cacheABCMobileAppSyncServiceBehavior"> <serviceMetadata httpGetEnabled="True" /> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
The error remains the same unfortunately :-(- Edited by Edgeman Wednesday, July 1, 2009 10:25 PM
Wednesday, July 1, 2009 10:20 PM -
Working now ... sort of...
To get it working I fixed the <custombinding> section in the client app to be the same as in the server app.
Now I am running into size issues while syncing 50,000+ records using the gzip encoder... I'll post back here if I can't get it to work by raising the buffer size, etc.
Thanks to all so far :-)- Proposed as answer by lxxx Saturday, March 20, 2010 7:36 AM
Thursday, July 2, 2009 1:58 AM -
Ok, I am now consistently getting "System.OutOfMemoryException" errors whenever I sync. It gets part of the way through, then throws that error.
Does anyone know which memory it's talking about? Is it the Buffer Size?
I guess I just need to bump it up ?
If anyone has ever experienced these errors and knows how to fix them I'd appreciate a pointer.
Thanks again!Thursday, July 2, 2009 2:06 AM -
I love it when I am able to learn & answer my own questions.
The "System.OutOfMemoryException" when away when I moved from Buffered to StreamedResponse, which meant the buffer never got filled, hence no System.OutOfMemoryException (I am assuming this btw).
So, all good & happy now. I have the encoder up and running, and in my latest test I synchronised 250,000+ records in about 11 minutes. This took well over 30 minutes before, and a *LOT* more bandwidth :-)
- Marked as answer by Edgeman Thursday, July 2, 2009 10:30 PM
Thursday, July 2, 2009 10:30 PM