vbs调用webservice实践

工作中用到,特此记录

Set   objArgs   =   WScript.Arguments
Dim url,xmlhttp,dom,node,xmlDOC
'根据webservice的测试页不同的方法构造不同的soap request
SoapRequest = "<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
    "<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
    "xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
    "xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
    "<soap:Body>"& _
    "<MyMethod xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _
     "<myparam>xxx</myparam>"& _
    "</MyMethod>"& _
     "</soap:Body>"& _
   "</soap:Envelope>"
url = "http://www.com//service.asmx?op=MyMethod"
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.loadXML(SoapRequest)
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
'SOAPAction这个Header头同样可以在sample中找到
xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/SendSms"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(xmlDOC)

posted @ 2010-11-03 14:49  lib  阅读(726)  评论(0编辑  收藏  举报