gzip C#/.NET

Overview of .NET usage in GWS

You can use .NET with GWS in the following manner (briefly stated). You can do the following when using .NET:

  1. Create a web service client proxy to encapsulate the calls to the web service following these steps:

    1. Open the project in Visual Studio.NET.

    2. Add a web reference to the web service to consume.

    3. .NET auto-generates the web service proxy code and adds it to the project.

  2. Create and initialize the proxy object with the following steps:

    1. Create an instance of the proxy in the code.

    2. Create a NetworkCredentials object with the account name and password, and sets the proxy's Credentials property to the new object.

    3. Set the proxy's Preauthenticate property to true. (This is supposed to cause the proxy to send the credentials on the initial request, but it doesn't work.)

    4. (Optional) Change the proxy's Timeout property (default is 100,000 ms) or the URL property (default is the URL specified in the WSDL file used to generate the proxy.)

  3. Call a method on the object.

  4. Process the response and handle exceptions.

Sample code overview

The .NET Framework does not provide compression support. In addition, there are a number of incorrect assumptions that the Framework makes about the best way to invoke a web service over HTTP. Performance recommendations for using GWS Web Services are included in this section. All of this is wrapped up into an assembly so that it can be easily integrated. Full source code is provided on the GWS sample site. The files for .NET are:

Performance recommendations assembly

The assembly is called GalileoHttpUtil. Here is a summary of the enhancements it provides:

NOTE: The term "pipelining" used sometimes used as a synonym for the term "connection pooling". However, the usage of these terms in this document is as follows:

How to use the sample code

The sample code has been provided in a zip file here, containing the complete source code
NOTE: This code was updated October 2011. If you have the original code, download the updated source code.

To use the sample code:

  1. Download the GalileoHttpUtil.zip file and extract it to your hard drive.

  2. Open the project in Visual Studio.NET.

  3. Add the GalileoHttpUtil project to the solution:

    1. In the solution explorer, right-click the solution.

    2. Choose Add.

    3. Choose Existing Project.

    4. Browse to the GalileoHttpUtil project folder.

    5. Select the GalileoHttpUtil.csproj file.

    6. Click OK.

  4. Assuming that you have already added the web reference steps above, open the .NET generated web service proxy code.

    1. Choose File > Open > File.

    2. Open the WebReferences folder.

    3. Open the folder for the web service to modify.

    4. Choose the Reference.cs file.

    5. Click Open.

  5. Find the line that looks like this: (this example uses the XmlSelect service - the class name will be different for each GWS service):

public class XmlSelect : System.Web.Services.Protocols.SoapHttpClientProtocol

  1. Change it to look like this:

public class XmlSelect : Galileo.Web.Services.EnhancedSoapHttpClientProtocol

  1. Provide the network credentials and set the PreAuthenticate property.

Providing the network credentials and setting the PreAuthenticate property are mandatory for GWS. Implement the following lines into your code:

// Manditory property settings to the proxy

NetworkCredential nc = new NetworkCredential(account, password);

xws.Credentials = nc;

xws.PreAuthenticate = true;

  1. Recompile.

Changing the inheritance from System.Web.Services.Protocols.SoapHttpClientProtocol to Galileo.Web.Services.EnhancedSoapHttpClientProtocol causes the generated proxy to inherit all the enhancements described above, and adds the following properties:

public bool Expect100Continue { get; set; } } Default: false

public bool KeepAlive  { get; set; } } Default: false

public bool UseNagleAlgorithm  { get; set; } } Default: false

public bool AcceptGZip  { get; set; } } Default: true

public bool GZipRequest  { get; set; } } Default: true

The default settings match best practice recommendations.