2013-01-23 65 views
1

我是編碼方面的初學者。如何使用vbscript調用Web服務調用

我不得不撥打以下Web服務: http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

輸入一個值,像25,然後單擊Invoke將返回華氏溫度。

對於我用下面的代碼:

url = "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit&Celsius=25" 
'Set oHttpReq = CreateObject("Microsoft.XMLHTTP") 'when i use XMLHTTP i am getting error saying "The download of the specified resource has failed." 

Set oHttpReq = CreateObject("MSXML2.ServerXMLHTTP") 'If i use it, the response contains Root Element missing 

oHttpReq.open "POST", url, False 
oHttpReq.send 

'Response 
responseText = oHttpReq.responseText 

WScript.echo responseText 

誰能幫助我?

+0

這也許可以幫助你http://www.codeproject.com/Articles/19359/Web-Service-Proxy-generator-using-XSLT-targeting-V –

+0

能有人闡明我的查詢一些輕。請讓我知道我要去哪裏錯了? – Uday

回答

1

在file.vbs(visual basic腳本)上創建 使用外部工具編譯爲exe 在服務器任務中設置此項。

Const HOST = Sample service in IIS 
Const URL = "wsPage.asmx" 

Set xmlhttp = CreateObject("Microsoft.XMLHTTP") 
xmlhttp.open "POST", HOST & URL & "/wsServiceTest", false 

'Set the Content-Type header to the specified value 
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 

' Send the request synchronously 
xmlhttp.send "" 
WScript.Echo "Load ok..."