This sample builds an XML-encoded request on the client and transmits it to an ASP page on the web server. The ASP page processes the request and generates an XML response that is returned to the client. The key idea in this sample is that we can submit a request to the server without forcing the existing web page on the client to be unloaded by the browser (as is the case with HTML

elements). A related and equally important idea is that we can transmit XML in the non-traditional sense: from the client to the server, and not just generate XML in response to a traditional client-based request.

More Details
This sample is based on the ADO, ASP and XML sample. Recall that the ADO, ASP and XML sample used a traditional HTML element to submit our query parameters to the ASP page on the server. In this sample, we still use an HTML element to collect input from the user. However, the client-side code intercepts the default processing of the HTML form through the DHTML event bubbling mechanism. It inspects the fields in the HTML form and generates an XML string that represents the request. The following is a sample XML-encoded request:

server pubs select * from titles

The client HTML code uses the XML HTTP Request object to issue the request to the server. The HTTP Request object allows us to transmit additional information within the body of an HTTP POST request. This is similar to how modern HTML forms that use the transmit the forms fields. We are simply overriding this default behavior of the web browser and transmitting instead the forms fields encoded as XML data. The client HTML code will show the XML request string prior to sending it to the server alongside the response XML that was generated by ADO.

The server ASP code reads the contents of the HTTP Post request into an instance of an XML Parser object on the server. How this can be done depends on the version of IIS that you are running the ASP script on. In IIS 5.0, it is a simple matter of instructing the XML parser to load its data from the ASP Request object. In IIS 4.0, it is a more complicated matter requiring compiled code that can deal with the SAFEARRAY of bytes that is returned by the Request.BinaryRead() method.

To get around this versioning problem, using a simple C++ COM adapter object will allow the same script to run on both IIS 4.0 and IIS 5.0. The programmatic identifier (PROGID) for this COM object is RequestExLib.RequestEx.

The script code retrieves the user parameters (computer name, database name, SQL string) from the XML parser object. It uses these parameters to generate an OLE DB connection string, and passes it along with the SQL statement to an ADO recordset object that is used to generate the XML response that is returned to the client.

Similar to the ADO, ASP and XML sample, the script conditionally generates XML from the ADO recordset object in a fashion that works with both IIS 4.0 and IIS 5.0.

Note that this sample must be manually copied to your web server. You can find the files that you need to copy in the XMLHTTP\XMLHTTP_Local subdirectory. To copy the source files to the web server, run the setup.cmd script in the XMLHTTP subdirectory. You must have the Windows Scripting Host installed to run this setup script.

Browser/Platform Compatibility
This sample requires Internet Explorer 5.0 on the client, and Internet Information Server 4.0 on the server. The Microsoft Data Access Components SDK Version 2.1 must be installed on the server. If you are running Windows 2000, the ASP scripts on the server will conditionally execute a different code path to take advantage of new features that are only available in the Microsoft Data Access Components SDK Version 2.5 and Internet Information Server 5.0.

Note: This sample also requires the RequestExLib.RequestEx COM object, which can be found in the RequestExLib.dll. You can find a copy of this DLL under the Tools\bin directory. It needs to be registered first (run regsvr32 on the file). This COM object is used to ensure that we can read code from an HTTP POST request into an XML Parser object instance using either IIS 4.0 or IIS 5.0.

Complete Article

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.