Web ASP Call WebService
----INDEX----
1. Soap Request method
2. Post Request method
3. Showallnode function (about node properties and data Display)
---------------------
A SOAP Request Sample
The following is an example of a SOAP request. The displayed placeholder needs to be replaced by the actual value.
Post/webservice1/usersignon.asmx http/1.1
host:192.100.100.81
Content-type:text/xml; Charset=utf-8
Content-length:length
SOAPAction: "Http://tempuri.org/LoginByAccount"
<?xml version= "1.0" encoding= "Utf-8"?>
<soap:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<loginbyaccount xmlns= "http://tempuri.org/" >
<username>string</username>
<password>string</password>
</LoginByAccount>
</soap:Body>
</soap:Envelope>
In order to interact with WebService, you need to construct a SOAP request that is identical to the one above:
<%
url = "Http://192.100.100.81/WebService1/UserSignOn.asmx"
soaprequest= "<?xml version=" &CHR (a) & "1.0" &CHR (a) & "encoding=" &CHR (+) & "Utf-8" & CHR & "?>" & _
"<soap:envelope xmlns:xsi=" &CHR & "Http://www.w3.org/2001/XMLSchema-instance" &CHR (a) & "" & _
"Xmlns:xsd=" &CHR & "Http://www.w3.org/2001/XMLSchema" &CHR (+) & "" & _
"Xmlns:soap=" &CHR & "http://schemas.xmlsoap.org/soap/envelope/" &CHR (+) & ">" & _
"<soap:Body>" & _
"<loginbyaccount xmlns=" &CHR & "http://tempuri.org/" &CHR (+) & ">" & _
"<username>" &username& "</username>" & _
"<password>" &password& "</password>" & _
"</LoginByAccount>" & _
"</soap:Body>" & _
"</soap:Envelope>"
Set xmlhttp = server. CreateObject ("Msxml2.xmlhttp")
xmlHTTP. Open "POST", Url,false
Xmlhttp.setrequestheader "Content-type", "Text/xml;charset=utf-8"
Xmlhttp.setrequestheader "HOST", "192.100.100.81"
Xmlhttp.setrequestheader "Content-length", LEN (Soaprequest)
Xmlhttp.setrequestheader "SOAPAction", "http://tempuri.org/LoginByAccount" must be the same as the WebService namespace, otherwise the service will reject
xmlHTTP. Send (Soaprequest)
' This makes use of XMLHTTP to successfully send a SOAP request with the SOAP sample.
' Check for success:
Response.Write XMLHTTP. status& ""
Response.Write XMLHTTP. StatusText
Set xmlhttp = Nothing
%>
If success will show OK, unsuccessful will show 500 internal server error? Connection:keep-alive.
Once successful, you can take advantage of the WebService response, as follows:
SOAP response Sample
The following is an example of a SOAP response. The displayed placeholder needs to be replaced by the actual value.
http/1.1 OK
Content-type:text/xml; Charset=utf-8
Content-length:length
<?xml version= "1.0" encoding= "Utf-8"?>
<soap:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<loginbyaccountresponse xmlns= "http://tempuri.org/" >
<LoginByAccountResult>string</LoginByAccountResult>
</LoginByAccountResponse>
</soap:Body>
</soap:Envelope>
This is an example of the SOAP response that corresponds to the sample SOAP request, and you can view the response after the request has been successfully sent:
If XMLHTTP. Status = Then
Set xmldoc =server. CreateObject ("MSXML"). DOMDocument ")
Xmldoc.load (Xmlhttp.responsexml)
Xmlstr = Xmldoc.xml
Set xmldoc=nothing
Xmlstr = Replace (Xmlstr, "<", "<")
Xmlstr = Replace (Xmlstr, ">", ">")
Response.Write Xmlstr
Else
Response.Write XMLHTTP. status& ""
Response.Write XMLHTTP. StatusText
End If
The correct request gives a full response, the request is incorrect (such as account number, password is not correct) the content of the response will be incomplete.
Remove the data from the response as follows:
If XMLHTTP. Status = Then
Set xmldoc = server. CreateObject ("MSXML"). DOMDocument ")
Xmldoc.load (Xmlhttp.responsexml)
Response.Write XmlDOC.documentElement.selectNodes ("//loginbyaccountresult") (0). Text ' Display data with Loginbyaccountresult nodes (encoded to decode)
Set xmldoc = Nothing
Else
Response.Write XMLHTTP. status& ""
Response.Write XMLHTTP. StatusText
End If