Calling Webservice from MS Word

S

sshah

Hi,

I was wondering if its possible to call a web service from MS Word,
Excel or Outlook. If so, are there any examples avaialable?

Thanks
Suneet
 
R

Roger R. Smith

I wrote a web service in Excel would you like me to send it to you ?
Thanks
Rog
 
S

sshah

Roger,

if you have an example of calling a webservice from excel, it would be
great if you could send it over. I may need to support versions of MS
Office prior to the 2003 version.

Thanks again for your help.
Suneet
 
D

Dino Chiesa [Microsoft]

can you not use the Office Web services toolkit?
or,
Just use VBA code that depends on MSXML like so
''''''''''''''''''''''''''''''''''''''''''''''

url= "http://dinoch.dyndns.org:7070/axis/services/StockQuote"

dim request

'' example only!
'' you need to replace this with your SOAP request
''
request= _
"<soap:Envelope" &_
" xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" &_
" xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'" &_
" xmlns:tns='http://localhost:7070/axis/services/StockQuote'" &_
"
xmlns:types='http://localhost:7070/axis/services/StockQuote/encodedTypes'"
&_
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" &_
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" &_
"<soap:Body" &_
" soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>" &_
" <q1:getInfo xmlns:q1='http://service'>" &_
" <symbol xsi:type='xsd:string'>IBM</symbol>" &_
" </q1:getInfo>" &_
"</soap:Body>" &_
"</soap:Envelope>"


WScript.Echo vbcrlf & "Posting request to: " & url & vbcrlf
dim xmlhttp
' must change this line to embed in MS-Excel or MS-Word
set xmlhttp = WScript.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", url, False
'xmlhttp.setRequestHeader "SOAPAction", "oof" ''required for Apache
AXIS, but could be anything?
xmlhttp.send request
' must use MEssageBox for debugging in MS-Exce;
WScript.Echo vbcrlf & "Raw XML response:" & vbcrlf
WSCript.Echo xmlhttp.responseXML.xml

dim response
set response= xmlhttp.responseXML ''this is an MSXML2.DOMDocument
response.setProperty "SelectionNamespaces",
"xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'"
dim oneNode
set oneNode=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body/soapenv:Fault")
if (oneNode is nothing) then
'set oneNode=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body")
'WSCript.Echo "SOAP BODY:"
'WSCript.Echo oneNode.xml

dim price
set price=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body/multiRef/lastSale
Price")
dim symbollastSalePrice
set symbol=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body/multiRef/symbol")

' must replace these for embedding in MS-Excel/Word
WSCript.Echo vbcrlf & "Last sale price:"
WSCript.Echo symbol.text & ": " & price.text

else
dim faultcode
set faultcode=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body/soapenv:Fault/fau
ltcode")
dim faultstring
set faultstring=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body/soapenv:Fault/fau
ltstring")
dim detail
set detail=
response.selectSingleNode("//soapenv:Envelope/soapenv:Body/soapenv:Fault/det
ail")
dim detailtext
if (detail is nothing) then
detailtext = "(none)"
else
detailtext = detail.text
end if

' must replace these for embedding in MS-Excel/Word
WSCript.Echo "SOAP FAULT: " & faultcode.text & vbcrlf & " " &
faultstring.text & vbcrlf & detailtext

end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,813
Messages
2,569,699
Members
45,489
Latest member
SwethaJ

Latest Threads

Top