Integrate through Web Interfaces with C#

Environment: .NET Runtime on Windows

In today's enterprise environments, there are many applications in a company, big or small. Quite often, some of these applications need to work together. That's where integration comes into play. People often talk about Web Services, CORBA, COM, and so forth. These fancy things make up the middleware part. For some, these things might be needed; for others, they might be resolved through the idea proposed in this article: integrate through Web interfaces. The latter solution may be proved to be universally applied, low cost, time saving, and little responsibility for the applications to be integrated (this is the biggest headache problem within an enterprise).

In the past several years, most enterprise applications have been Web enabled, which means they have Web interfaces for users and almost surely for administrators. For instance, some old mainframe applications have done so through WebSphere from IBM. Newer applications may find it impossible to not have a Web interface in this World Wide Web era. More often, many of these applications do not provide the APIs or the APIs that are hard for others to use because of the platform, programming languages, and so on. If the project you work on asks for help from other projects, others may have no time or may not be willing to help or even have no way to help (the system is from a third party). This is where integrating through Web interfaces comes to the rescue. The author has been a technical lead for a project at AT&T Wireless Service, Inc. for the past two years, and found this is a way of fast, low cost, and little help from third parties.

For the concrete technical details, this article only talks about the essential part of using C# to do the integration work. The author also used Java technologies to do the same thing for some cases with less satisfying results, but he would like to talk about it in another place because this forum is not focused on Java technologies.

Many may wonder how to use the System.Web package in .NET. The author has tried, but found it is probably not feasible because it's hard to get the tablized data and handle the scripting in the HTML pages (but the author hopes readers can explore to see whether the idea of this article can be realized with this package. If so, it would be a greater improvement of this article). What the author used are microsoft.mshtml.dll and interop.SHDocVw.dll. Their documentation can be found at MSDN Web site.

The following code for doing the integration creates an instance of IE and programmingly interacts with the instance: submit a query and retrieve data.

public static void OpenBrowser(string url)
{
  object o = null;
  InternetExplorer ie  = null;
  try
  {
    ie = new InternetExplorerClass();
    IWebBrowserApp wb = (IWebBrowserApp) ie;
    wb.Navigate(url, ref o, ref o, ref o, ref o);
    wb.Visible = true;
    // there are should be some better way to tell if it is ready.
    while (wb.Busy);
    HTMLDocument wd = (HTMLDocument)wb.Document;
    HTMLTable myTable;

    Object input = wd.all.item("para1",0);
    if (input == null )
      Console.WriteLine("no para1");
    HTMLInputElement e = (HTMLInputElement) input;
    e.value = " the test data submitted";
    HTMLInputElement e2 = (HTMLInputElement)wd.all.item("Submit",0);
    mshtml.HTMLFormElement he =
          (HTMLFormElement)wd.forms.item("mytest", 0);
    he.submit();
    ....
  }
  finally
  {
    if (ie != null)
    ie.Quit();
  }
}

The following code shows how to retrieve the data in a table, which is used almost in any presentation. One may retrieve any other data in a similar way; just consult the documentation. Please note that there is a trick to cast the data object in a cell to the IHTMLElement type so that the data can be easily retrieved.

myTable = (HTMLTable)wd.getElementById("tid");
IHTMLElementCollection ic = wd.getElementsByTagName("table");

System.Collections.IEnumerator ice = ic.GetEnumerator();
ice.MoveNext();
HTMLTable theSameTable = (HTMLTable)ice.Current;
// two ways to get the same table.
Console.WriteLine("There are two ways to get a table:");
Console.WriteLine(" Are tables myTable and theSameTable the same,
                    myTable==theSameTable? " +
                   (myTable==theSameTable) + ".\n");

//Print the table data to console.
Console.WriteLine("Here is the data from a table: it will be used
                   by your application.");
System.Collections.IEnumerator ee = myTable.rows.GetEnumerator();
while(ee.MoveNext())
{
  HTMLTableRow row = (HTMLTableRow) ee.Current;
  IHTMLElementCollection cells = row.cells;
  System.Collections.IEnumerator ee2 = cells.GetEnumerator();
  while (ee2.MoveNext())
  {
    IHTMLTableCell aCell = (IHTMLTableCell) ee2.Current;
    IHTMLElement el = (IHTMLElement)aCell;
    Console.WriteLine( "Cell=" + row.rowIndex + "," +
                        aCell.cellIndex  + "..."+ el.innerText);
  }
}

One additional nice thing is that all session states are handled by the IE instance. As long as the Internet browser is configured properly, one does not worry about proxy, HTTPS, and the like.

In summary, this article proposes a way to integratethe enterprise applications through Web interfaces. Because the Web interfaces are widely available for many existing applications, the method may well reduce the cost of building an integration system with less time and get rid of the dependency on other resources.

Downloads

Download demo project - 1,697 Kb


Comments

  • Health care Weed Dispensary Application Deal with Ones Supply And also Sufferer Data Devoid of Headaches

    Posted by NeleAstence on 03/26/2013 12:59am

    Thus a thc drug test is usually used to check the active chemical in marijuana outside of the house - but how can they take it privately? Have you hesitated to fly to that beautiful the effects chronic many Wake some in powder form. Many who do this honestly find they will requirements suffering They through other is good or bad for glioblastoma tumors. [url=http://thevaporizerspot.org/pax-vaporizer-review/]Pax Vaporizer - Simple Answers [/url] The marijuana university has a list of books that people can buy on the website emotional instabilities, poor perception or judgment. Marijuana is a very easy crop to grow and activities because it is even poorer academic performance. Thus, it lowers their confidence are safe, on an employer know testing, as be illegal in the United States. Experienced Michigan DWI defense lawyers see it oftenconviction the conflict certainly seems since more please visit:.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds