locked
Implementing GZip encoding using MSDN sample RRS feed

  • Question

  •     
    I've been tring to implement the <a href="http://msdn.microsoft.com/en-us/library/dd938879.aspx#UsingCompressiontoReduceDataTransferVolumesoverWCF">sample in MSDN</a> on how to reduce data transfer volumes using compression.
     
        // Create a CustomBinding
        System.ServiceModel.Channels.CustomBinding customBinding = 
            new System.ServiceModel.Channels.CustomBinding();
        
        // Create a compression binding element
        CompressionMessageEncodingBindingElement compressionBindingElmnt = 
            new CompressionMessageEncodingBindingElement();
       
        // ..and add to the custom binding
        customBinding.Elements.Add(compressionBindingElmnt); 
        
        // Create an HttpTransportBindingElement and add that as well
        HttpTransportBindingElement httpBindingElement = 
            new HttpTransportBindingElement();
        customBinding.Elements.Add(httpBindingElement); 
    
        System.ServiceModel.EndpointAddress endPoint =
            new System.ServiceModel.EndpointAddress(
                "http://myServer:8080/NorthwindDataCacheSyncService/");
    
        // Create the WCF proxy using the custom binding
        NorthwindDataCacheSyncContractClient proxy =
            new NorthwindDataCacheSyncContractClient(
                    customBinding, endPoint); 
    The code is extremely well commented, but I think there is a step missing from the sample because the last line (where it all comes together) is not explained where the customBinding/endPoint overload comes from?
    // Create the WCF proxy using the custom binding
    NorthwindDataCacheSyncContractClient proxy =
    new NorthwindDataCacheSyncContractClient(
    customBinding, endPoint);
    My WCF (sync) service just has a single (empty) constructor and not a constructor where you can pass a customBinding. It looks like I need to do something extra to create this interface? Does anyone know what you need to do here to do this...? Any help appreciated...
    • Moved by Max Wang_1983 Thursday, April 21, 2011 1:16 AM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Sunday, July 26, 2009 9:59 AM

Answers

  • Now solved: The 'missing step' was to use NETCFSvcUtil to generate the client proxy. (Solution found here - http://blogs.msdn.com/maagniho/archive/2008/12/24/gzip-message-encoding-for-wcf-applications-written-using-net-compact-framework.aspx)

    Step 2 – Use NetCFSvcUtil to generate the service metadata and compact framework client proxy

    2.1 NetCFSvcUtil is installed with the Power Toys for .NET Compact Framework 3.5. It is located in the following directory: \Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin. Make sure to add this path to you environment variable of you machine.

    2.2   Go to the Bin directory of the Server project in a command prompt and run the following commands in sequence

    (1)    NetCFSvcUtil.exe  Server.exe

    (2)    netcfsvcutil *.wsdl *.xsd /language:C#

    (1)    Will generate the metadata file required for code generation while (2) will generate the C# code for the client proxy.

    2.3   There will be two source files generated, CFClientBase.cs and …..array.cs. Rename …..array.cs to CFGeneratedCode.cs

    3.3 Copy the files CFClientBase.cs and CFGeneratedCode.cs created in step 2.2 to the project directory and add them to the project.

    • Marked as answer by SunHunter Sunday, July 26, 2009 12:13 PM
    Sunday, July 26, 2009 12:13 PM

All replies

  • Now solved: The 'missing step' was to use NETCFSvcUtil to generate the client proxy. (Solution found here - http://blogs.msdn.com/maagniho/archive/2008/12/24/gzip-message-encoding-for-wcf-applications-written-using-net-compact-framework.aspx)

    Step 2 – Use NetCFSvcUtil to generate the service metadata and compact framework client proxy

    2.1 NetCFSvcUtil is installed with the Power Toys for .NET Compact Framework 3.5. It is located in the following directory: \Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin. Make sure to add this path to you environment variable of you machine.

    2.2   Go to the Bin directory of the Server project in a command prompt and run the following commands in sequence

    (1)    NetCFSvcUtil.exe  Server.exe

    (2)    netcfsvcutil *.wsdl *.xsd /language:C#

    (1)    Will generate the metadata file required for code generation while (2) will generate the C# code for the client proxy.

    2.3   There will be two source files generated, CFClientBase.cs and …..array.cs. Rename …..array.cs to CFGeneratedCode.cs

    3.3 Copy the files CFClientBase.cs and CFGeneratedCode.cs created in step 2.2 to the project directory and add them to the project.

    • Marked as answer by SunHunter Sunday, July 26, 2009 12:13 PM
    Sunday, July 26, 2009 12:13 PM
  • An extra issue to note is that NetCFSvcUtil generates its own copies of the Microsoft.Synchronization.Data members which causes an ArgumentException error when syncing. The solution is to delete these types from CFGeneratedCode.cs and then all should work fine...

    "DELETE all the code, EXCEPT the interface, the ContractClient (which implements the interface) and the 8 classes which have in their names Request or Response for each of the four methods in the interface (for example a ApplyChangesResponse) .

    After that, add "using Microsoft.Synchronization.Data;" to the beginning of the file."


    (copied/edited from a solution mentioned in this thread - http://social.msdn.microsoft.com/forums/en-US/uklaunch2007ado.net/thread/9bebe986-9d28-4e7d-bd70-6fcd81e92c12 )


    Sunday, July 26, 2009 1:28 PM