Web Services - Server To Server With XMLHTTP

By Robbe D. Morris

Printer Friendly Version

Robbe Morris
Robbe & Melisa Morris

The concept of web services has been out there for awhile now and is starting to catch on.  Those of us who are used to standard web development practices for accessing relational databases might not see new opportunities that are right in front of us.  Such is the case with XML.  This article is designed to spark an interest in the server to server transfer of data arena.  It is important to note that this example does not implement SOAP specifically.  While the true definition of a web service does not require the use of SOAP, it is fast becoming one of the standard methods for accessing web services.  If you would like to read more, MSDN Web Services Defined I'd encourage you to do so.

Article Update - June 24, 2001 - Web Services - Server To Server With SOAP.
Related Article - August 22, 2001 - Insert Records - XML/ADO Marshalling Over The Net.
Related Article - September 6, 2001 - Single SOAP Message / Multiple ADO Recordsets.
Today, we'll just get you started with a bare bones example of web service source code needed for both the client side (server A) and server side (server B).  In the following code samples, we'll assume that both server A and server B are Windows 2000 servers running IIS 5.0 and also have the latest Microsoft XML Parser (3.0) and SDK installed.  When you view the server B code, take notice that it does not require the Microsoft XML toolset.  We'll show ADO as an example but you can place your database access code according to the platform that exists on the server.  All references to "client side" code actually mean the code is running on server A in ASP and not the visitor's browser.  Performing similar functionality via the visitor's browser is another article for another day.  Let's dig in...

Client Side (Server A or serverA.asp)
The client side code needs to access a remote system to retrieve data.  In this case, we want to retrieve an ADO recordset from a remote server.  To accomplish this, we'll ask the server B web service to reply with an XML data stream formatted specifically to allow us to load the server A ADO recordset with the XML data stream.  It is important to note at the time of this writing, ADO required specially formatted XML files/streams in order to load the data into an actual recordset.  It does not support loading of standard XML files.  With this in mind, we'll inform the server B web service that we want the data returned formatted for use with an ADO recordset.  In your usage of this process, you may want the XML stream returned in straight XML for use with XSL for eventual output to the user's browser.  Let's look at the code:

Server Side (Server B or serverB.asp)
The server side code will look very similar to pages you've written before.  Here, we'll look at the XMLREQUEST querystring value to determine whether the client side request wants an ADO formatted XML stream or a standard XML stream.  Once the XML stream is created, we simply write the content back to the browser as we normally would.  In our case, the output will actually be received by server A instead of the visitor's actual browser.  You'll want to develop your own standard for returning errors.  In this example, we use "XMLERR" as a flag in the first part of the stream to indicate we weren't successful.  Your implementation will likely be much more advanced.  Let's look at the code:

Now that you know how build a web service of your own, you can begin to consider ways in which this might benefit you.  Perhaps you want to designate a specific application server to interface with all of your different relational database servers.  Most operating systems (even the old ones) support HTTP and have (or easily could have) a web server process running on them.  Your company may have old legacy code/processes for accessing data that could be greatly enhanced or web enabled through your existing web architecture.  Whatever your situation, give XML based web services a second look as a potential solution to your needs.

Robbe has been a Microsoft MVP in C# since 2004.  He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.