Skip to main content
Omnitracs Knowledge Base

Modify reference.cs

Create an object using Microsoft.Web.Services2.WebServicesClientProtocol

Add the following using clause to the Form1.cs file of your application:

using DemoGetVehInf.qtref;

and instantiate the web service object

private DemoGetVehInf.qtref.QTWebSvcsServiceWse svc = new qtref.QTWebSvcsServiceWse();


Reference.cs is an auto-generated file that gets created by Microsoft.VSDesigner when you add the web reference. It will contain definitions for two classes. In the case of this demonstration you should find:

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



public class QTWebSvcsServiceWse : Microsoft.Web.Services2.WebServicesClientProtocol


Note that the QTWebSvcsServiceWse class is based on the WSE 2.0 WebServicesClientProtocol. This is the class you should use when using the Web Services Enhancements (WSE).

(info) The entry for your web reference in Solution Explorer should be expandable. If it is not, then go to the top of the solution explorer window, and select the toolbar button "Show All Files" as shown below.


Expand the web reference, expand, and then open (double-click) Reference.cs.

(info) The url of the web service is automatically placed into the file.

KeepAlive Issues




If you're using WSE 3.0, you must skip this section. Adding this section of code will break your application. If you're using WSE 2.0, you must include this section. Omitting it will break your application.

If you want to make only one web service request, you can skip this section. Most likely you will want to make more than one web service request per run of your application. In order to do this, you need to make these changes. First find the declaration of your web service class. This code already exists and should look like:

public class MyClassServiceWse : Microsoft.Web.Services2.WebServicesClientProtocol

Add this override into the MyClassServiceWse class.

protected override System.Net.WebRequest GetWebRequest(Uri uri)


    System.Reflection.PropertyInfo requestPropertyInfo = null;

    System.Net.WebRequest request = base.GetWebRequest(uri);

    if (requestPropertyInfo==null)

        requestPropertyInfo = request.GetType().GetProperty("Request");

    System.Net.HttpWebRequest webRequest =

        (System.Net.HttpWebRequest)requestPropertyInfo.GetValue(request, null);

    webRequest.KeepAlive = false;

    return request;


(info) The above problem has to do with a "KeepAlive" token that's inserted into the HTTP header. Historically, in the first version of HTTP (1.0), each request made to the server was made using a NEW socket connection. The overhead of this was realized, and then the KeepAlive connection was invented. Basically, the client sends a KeepAlive token along with the request. The server, when receiving this token, simply echoes it back to the client along with the response. When the client gets the response, with the KeepAlive set to true, he doesn't close the socket, and he re-uses it for subsequent requests. Then HTTP evolved and 1.1 became available, and the KeepAlive became obsolete. In HTTP 1.1, all connections are kept alive, unless explicitly stated otherwise. For whatever reason, the KeepAlive being set to true fouls things up. So we had to write code to set the KeepAlive to false. That's what the code above does.

Your solution should build successfully at this point.

Invoking the Web Service Method

  • Was this article helpful?