Editorials

You Really Can Make a REST Call Using COM

COM applications can communicate with RESTful web services quite handily. I found the easiest implementation was to use the COM dll Microsoft wrote for connecting to remote web sites. I believe it was intended to be used in an ActiveX enabled browser, exposing HTTP requests in a COM friendly manner, and capable of returning different result types. What I found interesting was that I was able to use this component to link a legacy application to a internal service using a Web API application as a gateway.

Any large company will constantly be developing or implementing new software to better meet their IT requirements. As new systems are brought online, other systems are modified to work with the new systems, or replaced by a new system. When the legacy application replacement cycle does not coincide with the cycle of other software on which it depends, one option is to have duplicate data entry, or something of that sort. Another is to try and get the two different systems to talk with each other.

This is the kind of situation where you may find yourself needing to use some older technology to talk with something that is capable of complex, modern communication, but can be utilized in a very simple way. RESTful calls are, by nature, about as simple as things can get. Data may be passed in a JSON string, which you can even create yourself should the need arise…the format is very simple. The HTTP transport is so simple you can even test some code in a Browser, or using a HTTP communication tool, or even CURL. If all you are doing is calling an HTTP Get command, passing all of your variables in a query string, it is really to test your calls in a browser.

Using a COM capable program you could write your entire HTTP communication stack yourself. You don’t have to. The XmlHTTP capabilities found in the MsXml2.dll and later allow you to directly communicate with your REST service much the same as you would using a Dot Net HttpClient object. You can add header information, make POST, PUT, GET, and DELETE calls, since you specify the verb required. All you need to add to the recipe is a valid URL and the necessary body if you are passing parameters outside of the URL.

Four Guys from Rolla have an interesting blog on this technique. Should you have some legacy code that may be accessible through COM, this may be a tool for you.

Cheers,

Ben