Accessing the AIRS Web Service using OLE/COM via VB.Net

The challenge was to connect to the Canadian Food Inspection Agency's (CFIA) Automated Import Reference System (AIRS) Validation Web Service from a basic scripting language (such as Revelations's OpenInsight). CFIA does not permit access via HTTP GET or POST while SOAP generates byte array data types for the XML content that the scripting language does not support.

 

We elected to use Visual Studio 2008's built-in functions to perform the byte-string data conversions and generate the SOAP interface. We also used Interop to make the properties and methods accessible via COM/OLE from the script. A setup project was created to generate the install package that automatically registered the COM objects on the client machine. All project documents are available on the AIRS download page

Terms of use

These resources and information are provided as freeware. Please provide a link back to this page (http://www.exorsys.com/AIRS) if you find this useful.

Specifications

The AIRSGateway project accepts all standard AIRS web service input parameters as properties and returns all available AIRS web service results as properties, substituting BYTE data types with STRING.

 

The GetResponse method returns a boolean response that evaluates to true (-1) when a successful web service call has been effected. Otherwise it returns zero with the Soap exception information in the "Error" properties.

 

Input properties

  • XmlRequest (required): input XML document
  • AirsVersion: defaults to "1.0"
  • Broker Key (required): Your actual Broker Key as assigned by the CFIA
  • Language: defaults to "1" (english) set to "2" for French
  • AirsURL: defaults to current web service URL

Output Properties

  • XmlResponse: XML document returned by Web Service
  • ErrorCode: from Soap Call
  • ErrorMessage: from Soap Call
  • ErrorDetail: from Soap Call

Download the complete AIRS Web Service Specifications

Create the project

  • Start Visual Studio 2008
  • Select: CreateProject/Window/ClassLibrary
  • Specify Solution Name: "AirsGateway"
  • OK

Prepare the main class module

  • Open Solution Explorer
  • Right-click Class1.vb, Rename, "AirsValidation"
  • Add the following lines before the class name;
  • Add the following code after the class name to create variables, define the interface and set default values;

Reference the AIRS Web Service

  • Right-click the solution name "AirsGateway" in the Solution explorer
  • Select: AddServiceReference/Advanced/AddWebReference
  • Specify URL: "http://airs-sari.inspection.gc.ca/avs/bvs.svc?wsdl"
  • Click GO to find the bvs service
  • Remove the (invalid) hyphen in the generated Web Reference Name suffix("-sari")
  • Click Add Reference

Call the Web Service

Create the method "GetResponse" to be used by the calling script by adding the following lines immediately before the "End Class" statement. This uses the dotNet GetBytes and GetString functions to convert to/from the Byte Array data type which is generated by the Web Service WSDL and is not supported by the scripting environment.

Generate the COM interface

  • Define the standard COM interface variables by "wrapping" the Class declaration as follows;
  • Add the COM GUID generator to VS2008 menus: Tools/External Tools/Add/Title: "Create GUID"/ Command: browse to "C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\guidgen.exe"/OK
  • Generate unique GUID keys: VS2008/Tools/Create GUID/4. Registry Format/New GUID
  • Cut-and-paste the Result value displayed to replace "xxx" in ClassID
  • Repeat previous 2 steps to assign unique GUIDs for InterfaceID and EventsID

Test the dotNet project

Create a simple Windows forms application that references the AIRSValidation project and executes the following code;

Test the COM interface

The following OpenInsight program demonstrates how the generated COM object can be accessed from a simple script

Creating the Windows Installer Setup Package

While the AIRSGateway project is open in VS;

  • Select File/New Project/Setup and Deployment
  • Name: "Setup"
  • Solution: "Add to Solution"
  • OK
  • Right-click "Setup" in Solution Explorer
  • Select: View/File System
  • Right-click "application folder"
  • Select: Add/Project Output/Pirmary Output/OK
  • Right-Click "AirsGateway.dll"
  • Select Properties Window
  • Set Register Property to "vsdraCOM"
  • Right-click "Setup" in Solution Explorer
  • Select Build to create setup.exe and .msi files

To access all project resources and results: view the AIRS download page.