Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to consume webservice from vbscript?

877 views
Skip to first unread message

ljb

unread,
Mar 9, 2004, 12:49:23 PM3/9/04
to
Anyone know how to consume webservice XML from desktop VBScript? I have the
following which loads and parses an XML file. I would like to try calling a
webservice.

Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False

If xmlDoc.Load(some_xml_file) Then
wscript.echo xmlDoc.documentElement.selectSingleNode("//PRTDESC").text
End If


thanks
LJB


ljb

unread,
Mar 9, 2004, 4:43:29 PM3/9/04
to
I've made some progress except I want the raw XML. How do I get that?

set SOAPClient = createobject("MSSOAP.SOAPClient30")
SOAPClient.mssoapinit("http://www.xmethods.net/sd/2001/TemperatureService.ws
dl")
wscript.echo "Temperature is: " & SOAPClient.getTemp("99821")

thanks
LJB


Wei-Dong XU [MSFT]

unread,
Mar 10, 2004, 5:14:12 AM3/10/04
to
Hi LJB,

If you are going to obtain the raw xml message, I'd suggest you can use the SoapConnector30, SoapSerializer30 and SoapReader30 to create the
SOAP request for the web service, then you can load the returned xml message into the SOAPReader. There is one code sample in the SOAP 3.0
toolkit documentation. Please search for the article: "Code Listing for the Execute Method". The SOAP toolkit 3.0 is available from the link:
SOAP Toolkit 3.0
http://www.microsoft.com/downloads/details.aspx?FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displaylang=en

Please feel free to let me know if you have any further questions.

Best regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


ljb

unread,
Mar 10, 2004, 8:19:41 AM3/10/04
to
Thank you for your help. I'm sorry I ended up posting similar questions both
here and in microsoft.public.excel.programming. In only discovered that
group yesterday and wasn't quite sure of its audience. I have long used this
vbscript group.

I found the Soap 3.0 tool kit yesterday and have installed it. Actually I
downloaded both Soap 2.0 and 3.0. When I got my code working based on
examples found in 2.0 I discovered the changes necessary to convert them to
3.0. Your suggestion to look at "Code Listing for the Execute Method" is
much appreciated. It does indeed look like it will provide a solution.

thanks
LJB


ljb

unread,
Mar 10, 2004, 2:07:10 PM3/10/04
to
I haven't tried SoapConnector30, SoapSerializer30 and SoapReader30 yet
because it looks complex. What advantages does that method offer over the
following?

Set xmlHttp = CreateObject("Msxml2.XMLHTTP.4.0")
Set xmlDoc = CreateObject("Msxml2.DOMDocument.4.0")
strUrl ="http://...../isPrime.asmx/IsPrime?n=11"
With xmlHttp
.Open "GET", strUrl, False
.send
if .Status = 200 then
xmlDoc.loadXML( .responseXML.xml)
else
.....some error

I'm not clear on how to call some webservices with my method. It works for
my example using
http://www.dev1.eraserver.net/D2S/WebServiceSample/isPrime.asmx/IsPrime?n=11
but not for others such as
http://www.xmethods.net/sd/CurrencyExchangeService.asmx/getRate?country1=japan&country2=usa
and
http://www.xmethods.net/sd/2001/TemperatureService.asmx/getTemp?zipcode=99821
I haven't determined the correct URL syntax/parameters I guess. The WSDL
documents exist for the latter but I'm not sure how to use them.

thanks
LJB


Wei-Dong XU [MSFT]

unread,
Mar 11, 2004, 6:38:35 AM3/11/04
to
Hi LJB,

When you send the web service request, you will need to send the saop message to server so that the server side will know how to provide
service to you. Since SOAP is based on http and XML, if you don't want to use other utility, in pure xml, you should create the soap request
yourself. I write one sample code for you.

The test web service is based on the Visual studio.net sample: Duwamish. You can install it in the default web site to perform one test on this. I
use the GetBooksByTopic method of the CatalogService service in this sample.

'VB Code begin ----------------------------------------------------
Sub SendSOAP()

Dim xmlhttp As New MSXML2.xmlhttp
Dim xmldoc As New MSXML2.DOMDocument40
Dim strUrl, strRequest As String
strUrl = "http://localhost/Duwamish7/service/catalogservice.asmx"

'we should build the SOAP request in xml so that server side will know what method
'we are requesting now with the arguments
strRequest = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<GetBooksByTopic xmlns=""http://tempuri.org/"">" & _
"<topicName>test</topicName>" & _
"<maxQty>1</maxQty>" & _
"</GetBooksByTopic>" & _
"</soap:Body>" & _
"</soap:Envelope>"

With xmlhttp
.Open "post", strUrl, False
.setRequestHeader "content-type", "text/xml; charset=utf-8"
.setRequestHeader "SOAPAction", "http://tempuri.org/GetBooksByTopic"
.send strRequest
If .Status = 200 Then
Debug.Print .responseXML.xml
End If
End With

End Sub
'Code end ------------------------------------------------------

Furthermore, with the help of SOAP Toolkit, you don't need to wrtie so many xml code. You can only specify enough information to SOAP object,
then they will perform the low level communication with server side and return the xml code back for you. I write one SOAP Toolkit sample code for
you which also use the same method of CatalogService service.

'Code begin ----------------------------------------------------
Sub fSOAPToolkit()
Debug.Print Execute("GetBooksByTopic", "test", 1)
End Sub

Function Execute(ByVal Method As String, _
ByVal A As String, _
ByVal B As Integer) As String

Dim Serializer As SoapSerializer30
Dim Reader As SoapReader30
Dim ResultElm As IXMLDOMElement
Dim FaultElm As IXMLDOMElement
Dim Connector As SoapConnector30

Const SoapAction = "http://tempuri.org/"
Const END_POINT_URL = "http://localhost/Duwamish7/service/catalogservice.asmx"
Const CALC_NS = "http://tempuri.org/"

Set Connector = New HttpConnector30
Connector.Property("EndPointURL") = END_POINT_URL
Connector.Connect

' binding/operation/soapoperation
Connector.Property("SoapAction") = SoapAction & Method
Connector.BeginMessage

Set Serializer = New SoapSerializer30
Serializer.Init Connector.InputStream

Serializer.StartEnvelope
Serializer.StartBody
Serializer.StartElement Method, CALC_NS
Serializer.StartElement "topicName"
Serializer.WriteString CStr(A)
Serializer.EndElement
Serializer.StartElement "maxQty"
Serializer.WriteString CStr(B)
Serializer.EndElement
Serializer.EndElement
Serializer.EndBody
Serializer.EndEnvelope

Connector.EndMessage

Set Reader = New SoapReader30
Reader.Load Connector.OutputStream
'Debug.Print Reader.RpcResult

If Not Reader.Fault Is Nothing Then
MsgBox Reader.FaultString.Text, vbExclamation
Else
'Execute = Reader.body.Text
Execute = Reader.Body.xml
End If

End Function
'Code end ------------------------------------------------------

From the SOAP Toolkit sample, you can find there is no need to build the xml string. All has been done by the object. That will be simple for your
development without spending more time on the xml string building.

For detailed information about the xml web service, this link will help you more.
Web Services Specifications Index Page
http://msdn.microsoft.com/library/en-us/dnglobspec/html/wsspecsover.asp

If you have any question regarding this issue, please feel free to let me know. I am standing by to be of assistance.

ljb

unread,
Mar 11, 2004, 12:55:46 PM3/11/04
to
That's a lot of information I will need to spend some time to digest. Again,
thank you very much.

thanks,
LJB

"Wei-Dong XU [MSFT]" <v-w...@online.microsoft.com> wrote in message
news:$Wt%23g11B...@cpmsftngxa06.phx.gbl...

Wei-Dong XU [MSFT]

unread,
Mar 11, 2004, 8:22:47 PM3/11/04
to
Hi LJB,

You are very welcome! Please feel free to let me know if you have any questions.

Have a nice weekend!

ljb

unread,
Mar 15, 2004, 3:33:41 PM3/15/04
to
In case anyone is interested I found a working demo of client-side SOAP at
http://www.soapuser.com/client4.html. Download the Excel file. Change the
URL from http://localhost:8080/... to http://services.xmethods.net/... if
you don't have a local web service running. I updated it to SOAP 3.0 and
MSXML 4.0 and it works great.


0 new messages