Use SOAP Toolkit 2.0 to provide existing code as a web service

zhaozj2021-02-08  241

Use SOAP Toolkit 2.0 to provide existing code as a web service

Built distributed applications using .NET

Steve Kirk and Priya Dhawan

Microsoft Developer Network

Summary: This article describes data conversions that use Microsoft SOAP Toolkit version 2.0 to provide existing Microsoft Visual Basic 6.0 code as a web service.

table of Contents

Introduction Data types provided by existing code

ADO 2X Command Objects ADO 2X Recordset Objects Summary Summary

Introduction Microsoft® Soap Toolkit Version 2.0 simplifies tasks that provide existing code as web services, SOAP Toolkit 2.0 Document (English) in the SDK section of MSDN Library. Some of the main features performed on the server side are to convert between data and XML messages (between web service clients and servers) in the existing code. The conversion of simple data types can be handled automatically, and more complex data types requires the developer to provide conversion code. Assess whether the existing code is suitable as a Web service, the data conversion problem discussed in this article is not the only problem that needs to be considered. Other factors that should be considered include objects and state models, returned data size, how to indicate that it has been successful, how to return to error messages, security models (including access control, authentication, and encryption), execute models (synchronous or asynchronous), how to distribute code , As well as transaction models (COM transactions or statements), and so on. These issues will discuss in the upcoming architectural topic (English) article. The data type provided by existing code To introduce all data types of existing code delivery to be a considerable project, so this article describes some of the most common data types. One alternative to convert through the SOAP Toolkit code is to extend existing code using an XML interface. This article discusses the conversion method of the following data types:

ADO 2X Command Objects ADO2X Recordset Objects Stream Objects XMLDOM Objects ADO 2X Command Object Direct Access Database Existing code often provides the Microsoft ActiveX® Data Object (ADO) Command object. Although a Command object cannot be passed between applications running in different processes, the object can be passed within the same process. For a single line of data entities, the output parameter of the Command object returns a higher data efficiency than returning through the ADO recordset. Therefore, ADO Command object is useful for returning a single line entity data. Reading the existing code in the following example returns an ADO COMMAND object that contains data as an output parameter. The code in the Custom Type Mapper is converted to the Command object using the SOAPSerializer object before passing to the Web service: with SOAPSERIALIZER

`Convert CommandType

.startElement "CommandType"

.writeString cmd.commandtype

.eelement

`Convert CommandText

.startElement "CommandText"

cmdText = cmd.comMandText

CmdText = Left (cmd.commandtext, len (cmdtext) - 8)

CmdText = Right (cmdtext, len (cmdtext) - 7)

.writeString cmdtext.endelement

`Convert Parameters Collection

.startelent "parameters"

For i = 0 to ocmd.parameters.count - 1

.startelement right (Ocmd.Parameters (i) .Name, _

Len (Ocmd.Parameters (i) .Name) - 1)

.startElement "Direction"

.writeString Ocmd.Parameters (i) .direction

.eelement

.startElement "Type"

.writeString Ocmd.Parameters (i) .type

.eelement

.startelement "size"

.writeString Ocmd.Parameters (i) .size

.eelement

.startelement "Value"

.writeString Ocmd.Parameters (i) .value

.eelement

.eelement

NEXT

.eelement

End with With Write Data The Parameter Parameters of the Command object is a very effective data transfer method. It can also expand and provide some type of check function. In the following example, the client submitted to the web service XML data is converted to the parameters of the ADO Command object, which will be passed to the existing code: DIM CMD as adod.command

Dim param as adodb.parameter

'pnode is MSXml2.ixmlDomnode that contains XML submitted by customers.

'Instantiate an ADO Command object

Set cmd = new adoDb.command

WITH CMD

'Application CommandType and CommandText

.Commandtype = _

Cint (pnode.selectsinglenode ("commandtype"). NodetypedValue)

.Commandtext = pnode.selectsinglenode ("CommandText"). NodetyPedValue

'Pack Parameters Collection

Set NodeParent = pnode.selectsinglenode ("parameters")

For i = 0 to NodeParent.childNodes.LENGTH - 1

Set nodeParameter = NodeParent.childNodes (i)

Set param = new adodb.parameter

With param

.Name = "@" nodeParameter.nodename

.DIRECTION = _

NodeParameter.Selectsinglenode ("Direction"). NodetypedValue

.Type = nodeparameter.selectsinglenode ("Type"). NodetypedValue

.Size = nodeparameter.selectsinglenode ("size"). NodetypedValue

.Value = factory.getmapper (enxsdstring, _

Nothing) .read (NodeParameter.selectsinglenode ("Value"), _Bstrencoding, EncodingMode, LFLAGS

End with

.Parameters.Append Oparam

NEXT

End with

The ADO 2X RecordSet object ADO 2x disconnected record set is often used to pass data between the layers of the multi-layer application. The data can be a single line, multi-line or hierarchy. In this example, the existing code returns an ADO Recordset object, which contains the hierarchical line data will be converted to XML, then return to the customer: DIM DOC AS MSXML2.DOMDOCUMENT

Set doc = new msxml2.domdocument

'Write record set data to XMLDOM

rs.save odoc, AdpersistXML

'Pass XML to SOAP Toolkit Serializer

SOAPSERIALIZER.WRITEXML DOC.XML

Write the data below, using XML that represents hierarchical row data, the object will be passed to an existing code: DIM RS as adoDb.recordset

DIM DOC AS MSXML2.DOMDOCUMENT

SET RS = New Adodb.Recordset

Set doc = new msxml2.domdocument

'Load XML into XMLDOMDocument

Doc.loadxml pnode.xml

'Use XML fill records from XmlDomDocument

The RS.Open Doc Stream object stream provides an effective way to pass data between the local layers of the application. It is the main method of reading XML from Microsoft SQL ServerTM 2000. In the following example, existing code returns an XML stream representing the hierarchical line data, which will be converted, then return to the customer: DIM Instream as adod.stream

'pvar contains a stream object returned by existing code

SET Instream = PVAR

'Passing XML data from streaming to SOAP Serializer

SOAPSERIALIZER.WRITESTRING Instream.ReadText XMLDOM Objects XMLDOM object is a good way to pass data between the local layers of the multi-layer application. It provides interface scalability, type check, and architectural authentication. Read the data below, the existing code returns an XMLDOMDocument object, the object will be converted, then return to the customer: `pvar contains XmldomDocument

PSoapSerializer.writexml pvar.xml

Write the data below, using XMLDOM objects that represent hierarchical row data (submitted by customers), then pass the object to existing code: set odoc = new msxml2.domDocument

'Load IXMLDOMNode XML into Domdocument objects

`pnode contains ixmldomnode object

转载请注明原文地址:https://www.9cbs.com/read-3030.html

New Post(0)