Server-side updates with soap and ASP

Source: Internet
Author: User
Tags closing tag constructor contains header soap object model variables xml parser

Client and server communication can take a custom protocol. However, SOAP provides a flexible, extensible, and simple solution for this purpose. Using the XMLHTTP object, the client browser can request that an ASP be executed on the server, and wait for the server to respond to continue. Because the original client page is not uninstalled, the entire process is transparent to the customer and is generally very fast.


The technology is discussed below through several demonstration pages. Since only Microsoft Internet Explorer 5 and higher versions support XMLHTTP, the example in this chapter will need to meet this minimum requirement if you want to work properly.

With extensibility in mind, I don't want to use a query string to pass a SOAP request because the length of this string is limited to 2048 bytes. Instead, I want to pass the request in the HTTP header, which does not have this limitation. Listing a shows how to use client JavaScript to send basic information to the server through an HTTP header.

Problems with soap

To provide the functionality of listing A, a SOAP request is issued to the server. This request consists of the following 4 parts:

The envelope contains the entire request and identifies the contained information as a SOAP request.
The package schema describes the information that constitutes the SOAP package.
The body contains the SOAP package.
The package contains actual information about the server request.
Because the SOAP document is also an XML document, it has the same limitations as any XML document. The most important of these is that the document must be "well-formed" (well-formed), which means two things.

First, the markup in a well-formed XML document must be closed. The easiest way to demonstrate this is to look at the difference between HTML and XHTML. In an XML document, all tags are container tags. Although this does not cause problems for container tags such as <span>, it is important to pay attention to non container tags such as

There are two ways to turn a non-container tag into a container tag. The first and most obvious approach is to add a closing tag (for example,

The second requirement of a well-formed XML document is that the attribute must be enclosed in single or double quotes. So, while <input type=text name=stuff/> is completely valid HTML, it is not well-formed XHTML and must be changed to <input type= ' text ' name= ' stuff '.

Soap documents also have none of the limitations of most other XML documents, that is, an XML Schema (XML Schema) must be used to describe the soap document. A schema is an abstract representation of the document structure and content written in XML, with the purpose of defining and describing the structure of the document for the XML parser.

The easiest way to create a SOAP document is to concatenate several strings. But it's easy to make mistakes. Instead, it is a better practice to use the MSXML XML Document Object Model (DOM) method to create a SOAP document. Creating a document This way ensures that the document is always well-formed. To do this, I created 6 JavaScript functions to encapsulate the DOM object of MSXML and create a SOAP document to set up, get, respond to a set or getting session variable request, send a SOAP document to the server, and parse a SOAP document. Listing b gives these functions; in the actual ASP page, they are referenced by an include statement.

XMLDOM, fault, and collection functions are mainly called by other functions. The role of the XMLDOM function is to return an instance of the latest version of the MSXML XML DOM object. The role of the fault function is to create an error soap document that indicates an error occurred. Collection is a class constructor that defines a JavaScript associative array.

The 4th function is Sessionsoap, which is also used as a class constructor, so that developers do not have to care specifically about how to create a SOAP document to handle session variables. The 5th function is sessionvariable, which handles the XMLHTTP logic required to interact with the server. The 6th function is Sessionparser, which is also a class constructor that parses a session variable soap document and gets the key/value pairs of the session variable. Listing C shows how to use these functions and classes in particular.


Server-side Scenarios

In addition to Sessionsoap and Sessionvariable, the client's JavaScript functions and classes can also be used on the server side. The reason for this design is to avoid writing client and server-side functions separately to accomplish the same task. Listing d shows the full soaptestclient.asp page, which is responsible for setting and getting session variables.

This example is a complete demonstration of how to use XMLHTTP, MSXML, and SOAP to access server-side information. These technologies can also be used for other purposes, such as updating an ASP Web page without regular unload/overload operations, and helping to speed up the application because of reduced communication with the server.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.