web| access is possible, most people think we need to run ASP.net or use SOAP Toolkit to access WebService
But this is not necessary, the use of Microsoft's XML parser we can also use the traditional ASP page to access WebService, I will show you a look at the following!
I will use three files to implement my presentation.
Global.asa, when the program starts running, use the application variable
I_soapcall.asp A containing file to access the SOAP service
Default.asp a basic ASP file to display SOAP data
Global.asa
When the website run Global.asa all the time, in Application_OnStart we add application variables
Source:
————————————————————————————————————————————
<script Language=vbscript runat=server>
Sub Application_OnStart
Dim aspnetresources
Aspnetresources = Getaspnetresources ()
Application ("aspnetexpires") = 12
If Len (aspnetresources) >0 Then
Application.Lock
Application ("aspnetresourcesupdated") =now ()
Application ("Aspnetresourcelist") =aspnetresources
Application.UnLock
End If
End Sub
</script>
<!--#include file= "i_soapcall.asp"-->
——————————————————————————————————————
When application first executes, we define a variable: Aspnetresources, whose value is the result of the function getaspnetresources (), which
A function can be found in the include file i_soapcall.asp, he returns a string, and then we define the expiration time variable:
Application ("Aspnetexpires"), we will use in default.asp, and finally we checked whether the getaspnetresources () was executed correctly and returned
Value length is greater than 0, if successful we need to record time application ("aspnetresourcesupdated"), and execution results
Application ("Aspnetresourcelist"). In the back I will tell you what these variables do!
Default.asp
Default.asp is used to show our WebService request.
——————————————————————————————————————————————
<%
Dim aspnetresources
If Len (Application ("Aspnetresourcelist")) >0 Then
If DateDiff ("H", now (), Application ("aspnetresourcesupdated")) > Application ("Aspnetexpires") Then
Aspnetresources = Getaspnetresources ()
Application.Lock
Application ("aspnetresourcesupdated") =now ()
Application ("Aspnetresourcelist") =aspnetresources
Application.UnLock
End If
End If
Response.Write Application ("Aspnetresourcelist")
%>
———————————————————————————————————————
Now it's the mystic i_soapcall.asp.
People think about the mysterious getaspnetresources () exactly what it looks like, you can use the basic ASP page call WebService, do not forget the SOAP service without
Whether the WSDL document or the execution result is an XML document, so we can parse (parse) it, it's not difficult!
In the function we use two object
Function getaspnetresources ()
Set soaprequest = Server.CreateObject ("MSXML2. XMLHTTP ")
Set myxml =server.createobject ("MSXML"). DOMDocument ")
Soaprequest is a server-side component that can send post and get requests.
myXML will be used to create an XML document for a SOAP service
————————————————————————————————————————————
Myxml.async=false
Soapurl = "Http://64.85.12.73/WebSvc/whatsnew123apx_ds.asmx/GetNew123aspXResources?"
Soaprequest.open "Get", Soapurl, False
Soaprequest.send ()
If not myxml.load (Soaprequest.responsexml) Then
returnstring = ""
Else
—————————————————————————————————————————————
We set Soapurl as our WebService URL and then we open the connection with the following statement
——————————————————————————————————————————————
Soaprequest.open "Get", Soapurl, False
_____________________________________________________________________________________________
The Soaprequest.open has five parameters, but only the first two are required, which means that the other three are free to choose from.
Parameter explanation:
Oserverxmlhttprequest.open Bstrmethod, bstrURL, Basync, Bstruser, Bstrpassword
Parameters
Bstrmethod
HTTP method used to open the connection, such as put or PROPFIND.
bstrURL
Requested URL. This must is an absolute URL, such as "http://Myserver/Mypath/Myfile.asp".
Basync (optional)
Boolean. Indicator as to whether the call is asynchronous. The default is False (the call does not
return immediately).
Bstruser (optional)
Name of the user for authentication.
Bstrpassword (optional)
Password for authentication. This parameter was ignored if the user parameter is Null or missing
Set up, we use Soaprequest.send () to send a request to the server, the results of the server returned as text stored in the Soaprequest.responsexml
All we have to do is construct this text.
Here's all the code for i_soapcall.asp.
<script language= "VBScript" runat= "Server" >
Function getaspnetresources ()
Dim returnstring
Dim myXML
Dim Soaprequest
Dim Soapurl
Set soaprequest = Server.CreateObject ("MSXML2. XMLHTTP ")
Set myxml =server.createobject ("MSXML"). DOMDocument ")
Myxml.async=false
Soapurl = "Http://64.85.12.73/WebSvc/whatsnew123apx_ds.asmx/GetNew123aspXResources?"
' This is the real available webservice
Soaprequest.open "Get", Soapurl, False
Soaprequest.send ()
If not myxml.load (soaprequest.responsexml) Then ' an Error loading XML
returnstring = ""
Else ' Parse the XML
Dim Nodesurl
Dim Nodesname
Dim nodesdateupdated
Dim Nodesdomain
Dim Numofnodes
Dim resourcelist
Dim I
REM--The XML Nodes are case sensitivve!
Set nodesurl=myxml.documentelement.selectnodes ("//url")
Set nodesname=myxml.documentelement.selectnodes ("//name")
REM--Uncomment the following lines if we want to access the dataupdated and the Domain Nodes
REM--set nodesdateupdated = myXML.documentElement.selectNodes ("//dateupdated")
REM--set nodesdomain = myXML.documentElement.selectNodes ("//domain")
REM--The number of nodes in the list
Numofnodes = Nodesurl.length
Resourcelist = "<font face=verdana size=2>latest asp.net resources</font><ul>"
For i = 0 to NumOfNodes-1
Resourcelist = resourcelist & "<li><a href=" & Nodesurl (i). Text & "><font Face=verdana size=2& gt; "&
Nodesname (i). Text & "</font></a></li>"
Next
Resourcelist =resourcelist & "</ul>"
returnstring = Resourcelist
Set Nodesurl = Nothing
Set Nodesname = Nothing
End If
Set soaprequest = Nothing
Set myXML = Nothing
Getaspnetresources = returnstring
End Function
</script>
The same creative ideas can be used in other programming languages.
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.