Integrating XML Web Services with VB6 Applications
by Max I. Fomitchev


Example 1:

    On Error GoTo WebServiceError
    Dim ws As New MSSOAPLib.SoapClient
    ws.mssoapinit "UltraMax.wsdl"
    WebService.LogOn "InvalidUserName", "InvalidPassword"
    ...
WebServiceError:
    MsgBox Err.Description & vbCr & ws.detail
    ...

Listing One
Dim WebService As New MSSOAPLib.SoapClient
WebService.mssoapinit _
  "http://www.UltraMax-Music.com/UltraMax.dll?Handler=GenUltraMaxWSDL"

Listing Two.
' Log on...
WebService.LogOn "MyUserName", "MyPassword"

Listing Three
(a)
Public FileName As String
Public Quality As Integer

(b)
Implements ISoapTypeMapper
Private mStringMapper As ISoapTypeMapper
Public Sub ISoapTypeMapper_Init( _
    ByVal pFactory As MSSOAPLib.ISoapTypeMapperFactory, _
    ByVal pSchema As MSXML2.IXMLDOMNode, _
    ByVal xsdType As MSSOAPLib.enXSDType)
    
    Set mStringMapper = pFactory.getMapper(enXSDstring, Nothing)
End Sub
Public Function ISoapTypeMapper_read(ByVal pNode As MSXML2.IXMLDOMNode, _
    ByVal bstrEncoding As String, ByVal encodingMode As _
    MSSOAPLib.enEncodingStyle, ByVal lFlags As Long) As Variant
    Dim fi As New FileInfo
    Dim Node As IXMLDOMNode
    fi.FileName = mStringMapper.read(pNode.selectSingleNode("FileName"), _
        bstrEncoding, encodingMode, lFlags)
    fi.Quality = mStringMapper.read(pNode.selectSingleNode("Quality"), _
        bstrEncoding, encodingMode, lFlags)
    Set ISoapTypeMapper_read = fi
End Function
Private Function ISoapTypeMapper_varType() As Long
    ISoapTypeMapper_varType = vbObject
End Function
Public Sub ISoapTypeMapper_write(ByVal pSoapSerializer As _
    MSSOAPLib.ISoapSerializer, ByVal bstrEncoding As String, _
    ByVal encodingMode As MSSOAPLib.enEncodingStyle, _
    ByVal lFlags As Long, pvar As Variant)
    Dim fi As New FileInfo
    Set fi = pvar
    pSoapSerializer.startElement "FileName"
    mStringMapper.write pSoapSerializer, bstrEncoding, encodingMode, _
        lFlags, fi.FileName
    pSoapSerializer.endElement
    pSoapSerializer.startElement "Quality"
    mStringMapper.write pSoapSerializer, bstrEncoding, encodingMode, _
        lFlags, fi.Quality
    pSoapSerializer.endElement
End Sub

Listing Four
(a)

Public SongTitle As String
Public AlbumTitle As String
Public Duration As Single
Public MP3Info As FileInfo

(b)
Implements ISoapTypeMapper
Private mStringMapper As ISoapTypeMapper
Private mFileInfoMapper As FileInfoMapper
Private Sub ISoapTypeMapper_Init( _
    ByVal pFactory As MSSOAPLib.ISoapTypeMapperFactory, _
    ByVal pSchema As MSXML2.IXMLDOMNode, _
    ByVal xsdType As MSSOAPLib.enXSDType)
    Set mStringMapper = pFactory.getMapper(enXSDstring, Nothing)
    Set mFileInfoMapper = New FileInfoMapper
    mFileInfoMapper.ISoapTypeMapper_Init pFactory, pSchema, xsdType
End Sub

Private Function ISoapTypeMapper_read(ByVal pNode As MSXML2.IXMLDOMNode, _
    ByVal bstrEncoding As String, ByVal encodingMode As _
    MSSOAPLib.enEncodingStyle, ByVal lFlags As Long) As Variant
    Dim si As New SongInfo
    Dim Node As IXMLDOMNode
    si.SongTitle = mStringMapper.read(pNode.selectSingleNode("SongTitle"), _
        bstrEncoding, encodingMode, lFlags)
    si.AlbumTitle = mStringMapper.read(pNode.selectSingleNode("AlbumTitle"), _
        bstrEncoding, encodingMode, lFlags)
    si.Duration = mStringMapper.read(pNode.selectSingleNode("Duration"), _
        bstrEncoding, encodingMode, lFlags)
    Set si.MP3Info = 
     mFileInfoMapper.ISoapTypeMapper_read(pNode.selectSingleNode("MP3Info"), _
     bstrEncoding, encodingMode, lFlags)
    Set ISoapTypeMapper_read = si
End Function
Private Function ISoapTypeMapper_varType() As Long
    ISoapTypeMapper_varType = vbObject
End Function

Private Sub ISoapTypeMapper_write(ByVal pSoapSerializer As _
    MSSOAPLib.ISoapSerializer, ByVal bstrEncoding As String, _
    ByVal encodingMode As MSSOAPLib.enEncodingStyle, _
    ByVal lFlags As Long, pvar As Variant)
    Dim si As New SongInfo
    Set si = pvar
    pSoapSerializer.startElement "SongTitle"
    mStringMapper.write pSoapSerializer, bstrEncoding, encodingMode, _
        lFlags, si.SongTitle
    pSoapSerializer.endElement
    pSoapSerializer.startElement "AlbumTitle"
    mStringMapper.write pSoapSerializer, bstrEncoding, encodingMode, _
        lFlags, si.AlbumTitle
    pSoapSerializer.endElement
    pSoapSerializer.startElement "Duration"
    mStringMapper.write pSoapSerializer, bstrEncoding, encodingMode, _
        lFlags, si.Duration
    pSoapSerializer.endElement

    pSoapSerializer.startElement "MP3Info"
    mFileInfoMapper.ISoapTypeMapper_write pSoapSerializer, _ 
                        bstrEncoding, encodingMode, lFlags, si.MP3Info
    pSoapSerializer.endElement
End Sub

Listing Five
<?xml version='1.0' ?> 
<servicemapping name='UltraMaxService'>
    <service name='UltraMaxService'>
        <using PROGID='UltraMaxMapper.FileInfoMapper' cachable='0' 
            ID='UltraMaxFileInfoMapperObject' />
        <using PROGID='UltraMaxMapper.SongInfoMapper' cachable='0'
            ID='UltraMaxSongInfoMapperObject' />
        <types>
            <type name='FileInfo' targetNamespace='urn:UltraMaxService'
                uses='UltraMaxFileInfoMapperObject'/>
            <type name='SongInfo' targetNamespace='urn:UltraMaxService'
                uses='UltraMaxSongInfoMapperObject'/>
        </types>
    </service>
</servicemapping>

Listing Six
Option Explicit
Implements IHeaderHandler
Public SessionID As String
Private Const NAMESPACE As String = "urn:UltraMaxService"
Private Const SESSIONID_NAME As String = "m_SessionID"
Private Function IHeaderHandler_readHeader(ByVal pHeaderNode _
    s MSXML2.IXMLDOMNode, ByVal pObject As Object) As Boolean
    If pHeaderNode.baseName = SESSIONID_NAME And _
        pHeaderNode.namespaceURI = NAMESPACE Then
        ' Read session ID
        SessionID = pHeaderNode.Text
        IHeaderHandler_readHeader = True
    Else
        IHeaderHandler_readHeader = False
    End If
End Function

Private Function IHeaderHandler_willWriteHeaders() As Boolean
    IHeaderHandler_willWriteHeaders = True
End Function
Private Sub IHeaderHandler_writeHeaders(ByVal pSerializer As _
                    MSSOAPLib.ISoapSerializer, ByVal pObject As Object)
    ' Write session ID
    pSerializer.startHeaderElement SESSIONID_NAME, NAMESPACE
    pSerializer.writeString SessionID
    pSerializer.endHeaderElement
End Sub






4


