Recently encountered a problem that requires you to call. NET webservice on asp and the client. That is to say, you need to use vbscript or javascript to call webservice. I checked it online. Most of the solutions use SOAP Toolkit. But this year, the SOAP Toolkit will be suspended for later support. To use soapclient, I need to install the SOAP Toolkit, this is not universal for the client, so I thought of using xmlhttp to interact With webservice.
The client code is as follows:
<Script language = "vbscript">
Set objHTTP = CreateObject ("MSXML2.XMLHTTP ")
Set xmlDOC = CreateObject ("MSXML. DOMDocument ")
StrWebserviceURL = "http: // localhost/possible/Service1.asmx/add"
'Set parameters and their values
StrRequest = "x = 2 & y = 3"
ObjHTTP. Open "POST", strWebserviceURL, False
'Setting this Content-Type is very important.
ObjHTTP. SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ObjHTTP. Send (strRequest)
BOK = xmlDOC. load (objHTTP. responseXML)
'Look at the status value
MsgBox objHTTP. Status
Msgbox objHTTP. StatusText
'Objhttp. Status = 200. Here we can process the returned xml snippet.
'If needed, replace & lt; and & gt; in the returned xml string;
XmlStr = xmlDOC. xml
XmlStr = Replace (xmlStr, "& lt;", "<", 1,-1, 1)
XmlStr = Replace (xmlStr, "& gt;", ">", 1,-1, 1)
Msgbox xmlStr
</Script>
The asp code on the server is changed:
<%
Set objHTTP = Server. CreateObject ("MSXML2.XMLHTTP ")
Set xmlDOC = Server. CreateObject ("MSXML. DOMDocument ")
StrWebserviceURL = "http: // localhost/possible/Service1.asmx/add"