----INDEX----
1. soap request method
2. post request method
3. SHOWALLNODE function (about node attributes and data display)
--------------------------
one. SOAP Request Example Below is an example SOAP request. The placeholders shown need to be replaced by actual values.
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 exactly the same as above:
<%
url = " http://192.100.100.81/WebService1/UserSignOn.asmx "
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>"& _
"<LoginByAccount xmlns="&CHR(34)&" http://tempuri.org/"&CHR(34 )&">"& _
"<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 namespace as WEBSERVICE, otherwise the service will be rejected
xmlhttp.Send(SoapRequest)
'This successfully sends a SOAP request that matches the SOAP example using XMLHTTP.
'Check whether it is successful:
Response.Write xmlhttp.Status&” ”
Response.Write xmlhttp.StatusText
Set xmlhttp = Nothing
%>
If successful, 200 ok will be displayed. If unsuccessful, 500 Internal Server Error will be displayed. Connection: keep-alive.
After success, you can use the response of WEBSERVICE, as follows:
SOAP Response Example Below is an example SOAP response. The placeholders shown need to be replaced by actual values.
HTTP/1.1 200 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 the SOAP response example corresponding to the SOAP request example just now. After the request is successfully sent, you can view the response:
If xmlhttp.Status = 200 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
If the request is correct, a complete response will be given. If the request is incorrect (for example, the account number and password are incorrect), the response content will be incomplete.
Get the data in the response as follows:
If xmlhttp.Status = 200 Then
Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
Response.Write xmlDOC.documentElement.selectNodes("//LoginByAccountResult")(0).text 'Display the data where the node is LoginByAccountResult (if it is encoded, it must be decoded)
Set xmlDOC = nothing
Else
Response.Write xmlhttp.Status&" "
Response.Write xmlhttp.StatusText
End if
displays the FUNCTION of each attribute and data of a node:
Function showallnode(rootname,myxmlDOC)' I hope everyone will continue to complete it. 2005-1-9 written by 844
if rootname<>"" then
set nodeobj=myxmlDOC.documentElement.selectSingleNode("//"&rootname&"")'Current node object
nodeAttributelen=myxmlDOC.documentElement.selectSingleNode("//"&rootname&"").attributes.length'The current number of node attributes
returnstring=returnstring&"<BR>Node name: "&rootname
if nodeobj.text<>"" then
returnstring=returnstring&"<BR>The text of the node: ("&nodeobj.text&")"
end if
returnstring=returnstring&"<BR>{<BR>"
if nodeAttributelen<>0 then
returnstring=returnstring&"<BR>There are "&nodeAttributelen&" attributes, which are: "
end if
for i=0 to nodeAttributelen-1
returnstring=returnstring&"<li>"&nodeobj.attributes(i).Name&": "&nodeobj.getAttribute(nodeobj.attributes(i).Name)&" </li>"
next
if nodeobj.childNodes.Length<>0 then
if nodeobj.hasChildNodes() and lcase(nodeobj.childNodes.item(0).nodeName)<>"#text" then'whether there are child nodes
set childnodeobj=nodeobj.childNodes
childnodelen=nodeobj.childNodes.Length
returnstring=returnstring&"<BR><BR>There are "&childnodelen&" child nodes;<BR>They are: "
for i=0 to childnodelen-1
returnstring=returnstring&"<li>"&childnodeobj.item(i).nodeName&"</li>"
next
end if
end if
returnstring=returnstring&"<BR>}<BR>"
response.write returnstring
set nodeobj=nothing
end if
End Function
It can be used like this:
If xmlhttp.Status = 200 Then
Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
showallnode "LoginByAccountResponse",xmlDOC'Call SHOWALLNODE
Set xmlDOC = nothing
Else
Response.Write xmlhttp.Status&" "
Response.Write xmlhttp.StatusText
End if
2. POST request example
HTTP POST
Below is an example HTTP POST request. The placeholders shown need to be replaced by actual values.
POST /WebService1/UserSignOn.asmx/LoginByAccount HTTP/1.1
Host: 192.100.100.81
Content-Type: application/x-www-form-urlencoded
Content-Length: length
username=string&password=string
Construct POST request:
<%
url = " http://192.100.100.81/WebService1/UserSignOn.asmx/LoginByAccount "
SoapRequest="username="&username&"&password="&password
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"'Note
xmlhttp.setRequestHeader "HOST","192.100.100.81"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(SoapRequest)
'This successfully sends a POST request that matches the HTTP POST example using XMLHTTP.
'Check whether it is successful:
Response.Write xmlhttp.Status&” ”
Response.Write xmlhttp.StatusText
Set xmlhttp = Nothing
%>
If successful, 200 ok will be displayed. If unsuccessful, 500 Internal Server Error will be displayed. Connection: keep-alive.
After success, you can use the response of WEBSERVICE, as follows:
HTTP POST
Below is an example HTTP POST response. The placeholders shown need to be replaced by actual values.
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<string xmlns=" http://tempuri.org/">string</string >
show:
If xmlhttp.Status = 200 Then
Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
showallnode "string",xmlDOC'call SHOWALLNODE
Set xmlDOC = nothing
Else
Response.Write xmlhttp.Status&" "
Response.Write xmlhttp.StatusText
End if
The above is the method for ASP to use XMLHTTP component to send SOAP request and call WEBSERVICE. I recommend using the first method in ASP environment. If there is a better method, please contact me mailto: [email protected] . If you use HTTP GET method There will be problems with Chinese, and the amount of data is not large. Using the HTTP POST method feels superfluous. In fact, the above example uses the POST method, but it is not a POST request. To use SOAP TOOLKIT, you need to install software, and there is no successor version. ---End of full text