My last article on How To Create A JSON Web Service in ASP.NET did not attract much interest so it is time to step it up a notch. To make this article more interesting Iâ€™m going to create a new web service in Fujitsu NetCOBOL. As far as I know, there are no examples on the Internet on how to do anything meaningful with the .NET Framework using the COBOL language. Although you can use many programming languages with .NET nobody really uses anything other than C# and VB.NET.
Letâ€™s suppose your company has senior management who often travel to Germany. Most of your expertise is in the COBOL programming language because the company has been using COBOL for years. And lets assume any new work must be done in COBOL as well to maintain the corporate IT culture. The executive puts in a request for a web service to help him find brothels while in Germany. You already have a web service that supplies him with client addresses from a contact database. He canâ€™t easily find information on brothels in Germany because he does not read German so youâ€™ll be maintaining a database of their locations.
Below is the database schema that we will be using for a database named Laufhaus with one table named ErosCenters:
Fujitsu NetCOBOL supplies an utility program which will add the necessary XML nodes to your web.config file for the database connection. This program will error until you run another utility program to update the machine.config. This was not well documented. Run the following command first: C:\Program Files\Common Files\Fujitsu NetCOBOL for .NET Runtime V3.0\Runtime\x86>setupconfig.exe /install
This will add the following section to your web.config file:
You can create a ASP.NET web service using COBOL as the language. It took me hours of experimentation to figure out how to turn a simple â€œHello Worldâ€ demo program into an actual web service. I had to work through how to make the database connection, how to return XML instead of a string, how to return multiple records, how to create an .NET object within COBOL, and how to call an object method. It was a hell of a lot of fun though to work in COBOL. As you can see this program is far more wordy than an equivalent program in C# would be.
Instead of a C# using namespace, you must alias a class in the REPOSITORY section. You define your string variables in the WORKING-STORAGE SECTION. Line 80 is where the database connection is being made. Then there is a query to determine how many records there are which tells you how many times to perform a routine. The database fields are moved to working storage strings which are then concatenated with XML tags. As you can see, just getting COBOL to build a string is hard work. A XmlDocument is created on line 130 and its LoadXml method is called to load the string that was built. This is what the web service returns.
Iâ€™ve used Eiffel for the .NET Framework but I would prefer COBOL since it can be used with the .NET Framework 2.0 and Visual Studio 2005. I learned COBOL in community college but never got the chance to use it professionally.
Please note that the brothel locator web service is intended as a joke. I just thought it would entice programmers to check out COBOL for the .NET Framework. My serious articles are often ignored. Nobody has actually requested this web service and it will not be used. It was purely a programming exercise. The nature of the data in the database is unimportant compared to the interesting choice of programming language and the technical challenge of making this work in COBOL.