|
Using SOAP广告 Using SOAP Sander Duivestein The Simple Object Access Protocol (SOAP) is a hot topic these days. The technology itself is simple, as shown by Sander Duivestein in this article. But the implications of its use are very exciting. It means that you'll be able to use objects and call methods located on other machines on the Internet. It doesn't matter what language they were written in nor what platform they're running on. SOAP solves all of those problems in one stroke! Right now I'm sitting behind my laptop in a hotel room in London. Each week I face the same trouble of getting back to the Netherlands. I have to call the travel agency that arranges my flight and train tickets. I'm totally dependent on the tight travel schedule given to me. Then I have to contact the hotel to make sure that I have a reservation for the following week. Why do I need to spend time on these issues every week? Isn't there a way that I could make those arrangements myself? Wouldn't it make life easier if there was a Web site that incorporated all of those third party services and offered them to the public? And how would that Web site incorporate all of these third party services? SOAP Microsoft describes SOAP this way: "SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It's an XML-based protocol that consists of three parts: an envelope that defines a framework for describing what's in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses. SOAP can potentially be used in combination with a variety of other protocols." In this article, I want to provide a sample application that uses SOAP to demonstrate how it can be put to practical use. Sample application ? SOAPClient.htm Authors.dll is a COM component that has two classes inside: clsConnectionManager, which manages ADODB connections, and clsRetrieve, which retrieves an ADODB recordset from the database.This example is simple, as it queries the Authors table of the MS SQL Server Pubs database. A client (SOAPclient.htm) contains a HTML form that has three elements. There are two text boxes and a submit button. A user can enter a firstname and/or a lastname and then submit the form by clicking the button. But this form isn't submitted in the same way that most forms are. When the Submit button is pushed, a Javascript function, SendSOAPRequest(), is triggered and the events specified in Table 1 happen. Table 1. The sequence of events that happen when the SendSOAPRequest() is triggered.
The SOAP specification declares that when using SOAP over HTTP, you have to define a HTTP header. This header contains several elements: ? An endpoint—Where the receiver of the SOAP request lives. This endpoint should match the location where you have put this example on the Web server. ? SOAPAction—The SOAPAction describes the purpose of the SOAP call; in this example, the purpose of the call is to invoke the method "GetAuthors" on the remote object "Authors.clsRetrieve." Firewall administrators can also use the SOAPAction attribute to block out certain SOAP calls. ? An indication that the mime-type of the header is XML. Setting the SOAP HTTP header is achieved using the Microsoft XMLHTTPRequest object (see Listings 1 and 2 ). Listing 1. How to set the HTTP header. var objXMLHTTP = _
Listing 2. How to build a SOAP request. function BuildSoapEnvelop()
{ ? A mandatory Envelope The Body element contains the methodname (GetAuthors) and the parameters of the method (FirstName and LastName). Submit the SOAP request objXMLHTTP.send(BuildSoapEnvelop());
'Get the HTTPHeader SOAPAction strSOAPAction =
_ Request.ServerVariables("HTTP_SOAPAction") 'Strip the
SOAPAction into two parts: ' the remote object and the methodname
strObject = _ Left(strSOAPAction, Instr(strSOAPAction, "#") -
1) strMethod = _ Right(strSOAPAction,
_ Len(strSOAPAction) - Instr(strSOAPAction,
"#")) 'Get FirstName and LastName from XML strFirstName =
_ objXML.getElementsByTagName("*").item(4).text strLastName =
_ Build SOAP response 'Query remote component Receive and show SOAP response //Show SOAP Response
Conclusion At this moment, there are several (free!) tools on the market that you can download to help build this kind of application yourself. The first one you should check out is the Microsoft SOAP toolkit on the Microsoft Web site. If you want to know more about SOAP, I suggest you take a look at the following Web sites. They provide a wealth of information: 如果您希望与本文章的作者或其所在机构,进一步交流,请联系:姜小姐 jill.jiang@amt.com.cn | 021-51096826-112 | 在线联系 |
CIO职场,强者生存?在2008年,我们将继续看到CIO向商业运营方向发展。与此同时,我们也会看到商业管理人员将与技术管理人员一起竞争CIO岗位。 IT领导者的就职机会虽有不少,但其难度将会大幅提高。2…… 防震减灾,IT当关今天,任何的防震救灾体系,都离不开IT技术。地震观测台是数字化的,震害防御需要对以往的地震信息进行数据分析,应急救援要需要现代多样化的通讯技术。如果说,在许多行业,信息技术还只是一…… |
|
|