How to Create Code-Based OpenSpan Solutions

OpenSpan Studio and its counterpart MS-Visual Studio plugin do a pretty good job when you have to integrate applications where you don’t have the source code available, service-enabled applications and/or exposed APIs. Having all the properties, events and methods graphically available make the development effort much easier than coding from scratch.

But, let’s say you’re an avid developer and feel pretty good handling code. Well, here is something you would really appreciate then. OpenSpan 4.5 has the capability of write automations directly in C#, VB or other .NET languages.

This is really powerful when you have the source code available and you want to drive your automations from a .NET-based application. Also, this approach would make the deployment sometimes simpler than the traditional approach.

Here is an example of code-based automation project:

1. Create a new .NET project. In this example we’ll be using a Visual C# project as the base project. Then, name it CodeBasedDemo.
2. You don’t the auto generated Form1.cs so feel free to remove it from your project.
3. In the same solution, create a new Empty OpenSpan project and name it CodeBasedOSDemo. Make sure you set the Solution field to Add to Solution instead of creating a new one.

4. Your solution should be similar to the following Solution Explorer image:

5. Now, it’s time to interrogate the required applications. We’re going to use a Windows-based application and a Web-based application for the purpose of the sample project. We’re not going to cover the interrogation process in details but feel free to take a look on the OpenSpan Online Help for more information. The OpenSpan Online Help is available at

6. After interrogating the two sample applications (MyCRM Windows-based application and the Web-based website) you should have something similar to the following in the Object Explorer panel:

Windows-based application

Web-based application

7. You’re now ready to dive into the code-based solution once everything we needed from the OpenSpan side is completed at this point. But before you start typing real code, make sure you import the right references to your .NET C# project. You may reference the same ones that OpenSpan automatically add when you interrogated the Windows and Web based applications.

8. Make sure you also add the CodeBasedOSDemo (the OpenSpan project) as a reference to your .NET C# project.
9. Right-click on your OpenSpan project and Build it to make all the necessary assemblies available to the parent project.
10. Open the Program.cs class file and create instances of the OpenSpan interrogated applications:

11. You’re ready to start interacting with the interrogated controls. Some of the possibilities like checking the state of checkboxes, making fields read-only, copying the required fields when the user take actions on any of the running applications, etc are listed on the commented code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace CodeBasedDemo
static class Program
//Create instances of the MyCRM and Fedex objects
static CodeBasedOSDemo.MyCRM myCRM = new CodeBasedOSDemo.MyCRM();
static CodeBasedOSDemo.Fedex fedex = new CodeBasedOSDemo.Fedex();

/// The main entry point for the application.

static void Main()
//Start Applications

//Make some fields Read-Only
myCRM.txttxtCreditLimit.ReadOnly = true;
myCRM.txttxtAccountBalance.ReadOnly = true;

//Handle the Do Not Call checkbox behavior
myCRM.cbDo_Not_Call.Click += new EventHandler(cbDo_Not_Call_Click);

//Handle the OK button click
myCRM.btnOK.Click += new EventHandler(btnOK_Click);
//Handle the Click on the Last Tracking Number label
myCRM.lblLast_Tracking_.Click += new EventHandler(lblLast_Tracking__Click);


// Close the Applications and shutdown the running instance
static void btnOK_Click(object sender, EventArgs e)

// Copy the Last Tracking Number from the MyCRM application
// to the text area on the Fedex website, perform the click on
// the Track button and return the Delivery Date to the Notes field
// on the MyCRM application. By the way, 3 lines of code to do that.
static void lblLast_Tracking__Click(object sender, EventArgs e)
fedex.textArea1.Text = myCRM.txttxtLastTrackNum.Text;
myCRM.txttxtNotes.Text = "Delivered Date: " + fedex.txtDeliveredDate.Text;


// Show or Hide the Phone field depending on the status of
// the Do Not Call checkbox
static void cbDo_Not_Call_Click(object sender, EventArgs e)
if (myCRM.cbDo_Not_Call.Checked)


12. Set the CodeBasedDemo project as the startup project of your solution

13. When you finish coding your automations, copy the .dll files under the CodeBasedOSDemo\bin\Debug directory to CodeBasedDemo\bin\Debug
14. Build the solution and run it.

If you have any problems building the solution take a look on the first few lines of the exception as it can point you to probably missing libraries in your project.

The sample code for this tutorial is also available here: Code-Based Demo Source


Popular posts from this blog

Calling Web Services with Apache Camel

How to Declare Variables in MS-SQL Server Management Studio

Using HTTP-based endpoints with Apache Camel