HttpWatch Automation Reference - Version 12.x
Using HttpWatch Automation with C# / C# - Overview
In This Topic
    C# - Overview
    In This Topic

    Referencing the HttpWatch Automation Library

    Either use Visual Studio to set up a new project, or choose an existing project to modify.

    Since the HttpWatch automation library is packaged as a COM component, its types are accessed in the same way as any other COM component.

    Give the project access to the library by adding a reference as follows:

    1. Go to the Project -> Add Reference menu item in Visual Studio. (Alternatively, expand the project's node in the Solution Explorer panel, then right-click on the References node and choose "Add Reference..." from the context menu.)

    2. When the Add Reference dialog appears, click on the COM tab.

    3. Find the 'HttpWatch Automation Library' in the list and select it as shown here:


    HttpWatch Namespace

    The namespace for the library is HttpWatch. Source code modules that access the library must either contain a using statement that references the library:


    Referencing the HttpWatch namespace
    Copy Code
    using HttpWatch;   // Reference the HttpWatch namespace
    Controller controller = new Controller();


    or else each reference to a class in the library must be prefixed by the namespace name:


    Opening a Log File
    Copy Code
    // Qualify each class reference with "HttpWatch."
    HttpWatch.Controller controller = new HttpWatch.Controller();
    HttpWatch.Log log = controller.OpenLog(@"c:\temp\test.hwl");

    Communicating with the HttpWatch Plug-In

    You can only directly create an instance of one class in the library - the Controller class.

    All communication with the HttpWatch plug-in stems from this class, so the first step is to create an instance of it:


    Creating the Controller
    Copy Code
    // Controller is the only creatable class in the HttpWatch automation interface
    HttpWatch.Controller controller = new HttpWatch.Controller();


    It is possible to use ControllerClass instead of Controller as the object type. ControllerClass is effectively an alias for Controller, createded by the process of importing the Type Library into the .NET environment. However, Controller is the preferred usage.

    Having created a Controller object, the next step is to create an instance of the plug-in and attach it to a browser instance. The exact code depends on whether you are using Internet Explorer or Chrome, but the principles are the same in either case. The Controller object has property named IE. This property returns a references to the IE object.

    The IE object offers two methods, New and Attach. The New method creates a new instance of the browser with an HttpWatch add-on embedded within it. Attach allows the user to create an HttpWatch add-on and embed it in a browser instance that has already been created by some other component. Both methods return a reference to the Plugin object that represents the HttpWatch plug-in.

    The following code creates a new instance of Internet Explorer with an embedded HttpWatch plug-in component:


    Creating the HttpWatch plug-in for IE
    Copy Code
    HttpWatch.Controller controller = new HttpWatch.Controller();
    HttpWatch.Plugin plugin = controller.IE.New();

    Instances of Internet Explorer are referenced through the IE IWebBrowser2 interface, so the IE object's version of the Attach method takes an IWebBrowser2 reference:


    Attach HttpWatch to existing instance of IE
    Copy Code
    // You could have previously created your own instance of IE
    // directly or using an automation framework
    SHDocVw.IWebBrowser2 ieBrowser = new SHDocVw.InternetExplorer();
    ieBrowser.Visible = true;    // Required to see the new window
     . . .
    HttpWatch.Controller controller = new HttpWatch.Controller();
    HttpWatch.Plugin plugin = controller.IE.Attach(ieBrowser);


    Alternatively, to attach to the HttpWatch extension for Chrome use the New method of the Chrome class:

    Creating the HttpWatch plug-in for Chrome
    Copy Code
    HttpWatch.Controller controller = new HttpWatch.Controller();
    HttpWatch.Plugin plugin = controller.Chrome.New();

    All of these code fragments return a reference to a Plugin object, through which the HttpWatch plug-in can be controlled.

    See Also