[AccessD] Web Service

MartyConnelly martyconnelly at shaw.ca
Sun Mar 16 18:29:01 CST 2003


Mwp.Reid at Queens-Belfast.AC.UK wrote:

>Anyone know the address of a demo web service I can link to in an application.
>
>
>Martin
>
>  
>
 Here is some Access Code for a working web service  Partial UK Postal Codes


'references to XML 4.0 Library  & MS SoapType Library v3.0
' http://www.webservicex.net/uklocation.asmx
'http://www.salcentral.com/asp/spec.asp?WSURL=http://www.webservicex.net/uklocation.asmx?WSDL
' http://www.webservicex.net/WS/default.aspx

Function testMSSoap()
'this just returns an XML file string from web service
'for UK Postal Codes
Dim soapClient
Dim strWSDL As String

Set soapClient = CreateObject("MSSOAP.SoapClient30")
On Error Resume Next
 'WSDL location and namespace info
   strWSDL = "http://www.webservicex.net/uklocation.asmx?WSDL"

Call soapClient.MSSoapInit(strWSDL, "", "", "")
  If Err <> 0 Then
    Debug.Print "initialization failed " + Err.Description
   End If

  On Error GoTo ErrSoap
'Get Postal code of town
Debug.Print soapClient.GetUKLocationByTown("Largs")

' Get all UK towns,Postcode and County by Postcode(First Section of Post 
Code)
Debug.Print soapClient.GetUKLocationByPostCode("KA30")

Bye_testMSSoap:
  Exit Function

ErrSoap:
  Beep
  MsgBox Err.Description, vbExclamation
    Debug.Print "faultcode=" & soapClient.FaultCode
    Debug.Print "faultstring=" & soapClient.FaultString
    Debug.Print "faultactor=" & soapClient.FaultActor
    Debug.Print "detail=" & soapClient.Detail
  testMSSoap = Null
  Resume Bye_testMSSoap

End Function


Function testMSSoapXML()
'this returns and parses an XML file string
'from webservice via xpath for UK Postal Codes

Dim soapClient As Object
Dim strWSDL As String
Dim strXML As String
Dim xslDoc As MSXML2.DOMDocument40
Dim xmlDoc As MSXML2.DOMDocument40

Set xmlDoc = New MSXML2.DOMDocument40
Set xslDoc = New MSXML2.DOMDocument40
Set soapClient = CreateObject("MSSOAP.SoapClient30")
'On Error Resume Next
 'WSDL location
   strWSDL = "http://www.webservicex.net/uklocation.asmx?WSDL"

Call soapClient.MSSoapInit(strWSDL, "", "", "")
  If Err <> 0 Then
    Debug.Print "initialization failed " + Err.Description
   End If

 ' On Error GoTo ErrSoap
'Get Postal code of town
'Debug.Print soapClient.GetUKLocationByTown("Largs")

' Get all UK towns,Postcode and County by Postcode(First Section of Post 
Code)
strXML = soapClient.GetUKLocationByPostCode("KA30")

Debug.Print strXML

xmlDoc.LoadXml strXML

If xmlDoc.parseError <> 0 Then
     Debug.Print xmlDoc.parseError.reason & vbCrLf & _
      xmlDoc.parseError.linepos & _
     xmlDoc.parseError.Line & _
     vbCrLf & xmlDoc.parseError.srcText
End If

  Dim retXML As IXMLDOMNodeList
  Dim node As IXMLDOMNode
'XPath expression into select nodes 'tutorial at www.zvon.org
Set retXML = xmlDoc.selectNodes("//NewDataSet") ' Table Names
     
      Dim i As Integer
      For Each node In retXML
          For i = 0 To node.childNodes.length - 1
              MsgBox node.childNodes.Item(i).text
              Debug.Print node.childNodes.Item(i).text
          Next i
      Next node
 
Bye_testMSSoap:
  Exit Function

ErrSoap:
  Beep
  MsgBox Err.Description, vbExclamation
    Debug.Print "faultcode=" & soapClient.FaultCode
    Debug.Print "faultstring=" & soapClient.FaultString
    Debug.Print "faultactor=" & soapClient.FaultActor
    Debug.Print "detail=" & soapClient.Detail
  testMSSoap = Null
  Resume Bye_testMSSoap

End Function





More information about the AccessD mailing list