You can use .NET with GWS in the following manner (briefly stated). You can do the following when using .NET:
Create a web service client proxy to encapsulate the calls to the web service following these steps:
Open the project in Visual Studio.NET.
Add a web reference to the web service to consume.
.NET auto-generates the web service proxy code and adds it to the project.
Create and initialize the proxy object with the following steps:
Create an instance of the proxy in the code.
Create a NetworkCredentials object with the account name and password, and sets the proxy's Credentials property to the new object.
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.)
(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.)
Call a method on the object.
Process the response and handle exceptions.
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:
ICSharpCode.SharpZipLib.dll
The assembly is called GalileoHttpUtil. Here is a summary of the enhancements it provides:
gzip compression - you can choose whether to accept GZip compression on the response, and whether to gzip the request. Both request and response are compressed by default. The two options are independent of each other. You can optionally turn off compression for either the request or the response.
Expect 100-Continue - Using of 100-continue adds anywhere from 25 to 150 milliseconds on a typical transaction, and network delays could make it much more. Everyone should disable 100-Continue when using GWS services. Unfortunately, the framework hides it, whereas the sample code makes it a simple property setting on the web service proxy.
KeepAlive - Using the Connection: KeepAlive header on HTTP 1.1 causes the Framework to pool HTTP connections.* Connection pooling can provide some savings by eliminating the time to establish a connection (when connections are available in the pool). However, it can also happen that connections in the pool get closed by the server. Depending on when this happens, this can result in a web service call getting an exception with a connection error. Using a new socket for every connection may add a little connection time (usually only milliseconds if you have a fast network connection), but it is also more reliable because you are less likely to encounter connection exceptions. Galileo’s recommendation is to use neither connection pooling, nor pipelining, when using Galileo Web Services.
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:
Connection Pooling - Reusing an HTTP connection for multiple HTTP request. When the connection is idle, it is kept in a pool of available connections.
Pipelining - Performing multiple, simultaneous HTTP requests on a single HTTP connection.
Using these definitions, it may be possible to do connection pooling, pipelining, or both at once, but neither is recommended with GWS.
Nagle Algorithm - The Nagle Algorithm was created to make TCP traffic more efficient, but for web services it doesn't help, and can cause delays of 200 ms. From the extensive network analysis, Nagle delay happens a lot more than one would expect. Recommendations are to turn off the Nagle Algorithm. The code shows that this is also a property setting.
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:
Download the GalileoHttpUtil.zip file and extract it to your hard drive.
Open the project in Visual Studio.NET.
Add the GalileoHttpUtil project to the solution:
In the solution explorer, right-click the solution.
Choose Add.
Choose Existing Project.
Browse to the GalileoHttpUtil project folder.
Select the GalileoHttpUtil.csproj file.
Click OK.
Assuming that you have already added the web reference steps above, open the .NET generated web service proxy code.
Choose File > Open > File.
Open the WebReferences folder.
Open the folder for the web service to modify.
Choose the Reference.cs file.
Click Open.
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 |
Change it to look like this:
public class XmlSelect : Galileo.Web.Services.EnhancedSoapHttpClientProtocol |
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; |
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.