Use vbscript to call web Services

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.