ASP calls Web Service

Source: Internet
Author: User

First, send the request and then process the response. I directly access the WebService written in. net. Click the method name to view the instance.CodeIn ASP, you only need to use Microsoft. XMLHTTP to send a request, and then process the XML results.

Note that the namespace cannot be written incorrectly.

<% @ Language = VBScript codePage = 936%>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
</Head>
<Body>
<%
Dim strxml
Dim Str

'define a SOAP message
strxml = " "
strxml = strxml &" "
strxml = strxml &" "
strxml = strxml &" "
strxml = strxml &" 4dv5esfhah0 = "
strxml = strxml &" not. cente "
strxml = strxml &" "
strxml = strxml &" "
strxml = strxml &" "

Set H = Createobject ("Microsoft. XMLHTTP ")
'Send post message to the specified URL
H. Open "Post", "http: // 192.168.3.239: 8000/3 des/service. asmx", false
H. setRequestHeader "Content-Type", "text/XML; charset = UTF-8"
H. setRequestHeader "Content-Length", Len (strxml)
H. setRequestHeader "soapaction", "http: // 192.168.3.239: 8000/3 des/decrypt"
H. Send (strxml)

'Display returned XML Information

If H. Status = 200 then
Set xmldoc = server. Createobject ("MSXML. domdocument ")
Xmldoc. Load (H. responsexml)
STR = xmldoc. childnodes (1). text'' call showallnode

'Traverse and retrieve a node in XML
Set node = xmldoc. getelementsbytagname ("regionid ")
'For x = node. Length-1 to 0 step-1
Regmgrid = node. Item (0). Text
'Next

Set xmldoc = nothing
Response. Write (STR)
Else
Response. Write H. Status & "& nbsp ;"
Response. Write H. statustext
End if

%>
</Body>
</Html>

Convert to another

ASP calls WebService
---- Index ----
1. Soap Request Method
2. POST Request Method
3. showallnode function (displays attributes and data of nodes)
---------------------
I. SOAP request example
The following is a SOAP request example. The displayed placeholder must 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"





string
string



to interact With WebService, You need to construct a SOAP request identical to the preceding one:
<%
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 as the WebService namespace, otherwise the service will reject
XMLHTTP. send (soapr Equest)
'. In this way, XMLHTTP is used to successfully send a SOAP request that matches the soap sample.
'check whether the response is successful:
response. write XMLHTTP. status & "& nbsp;"
response. write XMLHTTP. statustext
set XMLHTTP = nothing
%>
If the call succeeds, 200 OK is displayed. If the call fails, 500 internal server error is displayed? Connection: keep-alive.
after successful connection, you can use the WebService response as follows:
soap response example
below is a soap response example. The displayed placeholder must be replaced by the actual value.
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 = "The http://www.w3.org/2001/xmlschema-instance" xmlns: XSD = "The http://www.w3.org/2001/xmlschema" xmlns: Soap = "The 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. After the request is successfully sent, you can view the response:
If xml http. Status = 200 then

Set xmldoc = server. Createobject ("MSXML. domdocument ")
Xmldoc. Load (XMLHTTP. responsexml)
Xmlstr = xmldoc. xml
Set xmldoc = nothing
Xmlstr = Replace (xmlstr, "<", "& lt ;")
Xmlstr = Replace (xmlstr, ">", "& gt ;"

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.