ASP invokes WebService document

Source: Internet
Author: User
Tags chr soap string version xmlns
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=" &AMP;CHR (a) & "1.0" &AMP;CHR (a) & "encoding=" &AMP;CHR (+) & "Utf-8" & CHR & "?>" & _
"<soap:envelope xmlns:xsi=" &AMP;CHR & "Http://www.w3.org/2001/XMLSchema-instance" &AMP;CHR (a) & "" & _
"Xmlns:xsd=" &AMP;CHR & "Http://www.w3.org/2001/XMLSchema" &AMP;CHR (+) & "" & _
"Xmlns:soap=" &AMP;CHR & "http://schemas.xmlsoap.org/soap/envelope/" &AMP;CHR (+) & ">" & _
"<soap:Body>" & _

"<loginbyaccount xmlns=" &AMP;CHR & "http://tempuri.org/" &AMP;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



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.