- 本站大部分内容从网上收集,收集目的仅供研究、学习。涉及版权或不希望收录您的文章请您及时与我联系。
- 本站IM群,请自行选择。请各位朋友按照自己喜好加入。加入群后请及时发言,防止被清理。谢谢您的合作!!!
- QQ群:Y①WEB开发(ASP.NET)号码:7351660 QQ群:Y②WEB开发(ASP+.NET)号码:11864905
- QQ群:Y③WEB开发(DIV+CSS)号码:16610506 QQ群:Y④WEB开发(JS+AJAX)号码:16143998
- QQ群:Y⑤WEB开发(新手)号码:12777715 MSN群:yaosansi[at]126.com
我将使用三个文件来实现我的展示。
global.asa,当程序开始运行时,使用application变量
i_soapcall.asp 一个包含文件,用以访问soap service
default.asp 一个基本的asp文件,用以显示soap数据Global.asa
当website运行时global.asa时刻都在运行,在application_onstart中我们加入application变量
当application第一次执行时,我们定义了一个变量:ASPNETResources,它的值是函数GetASPNetResources()的执行结果,这个函数可以在包含文件i_soapcall.asp中找到,他返回一个字符串,随后我们定义了过期时间的变量:
Application("ASPNETExpires"),我们将在default.asp中使用,最后我们检查了GetASPNetResources()是否执行正确,返回值长度是否大于0,如果成功我们需要纪录时间 Application("ASPNETResourcesUpdated"), 和执行结果Application("ASPNETResourceList"). 在后面我将告诉大家这些变量是做什么的!
Default.asp
default.asp是用来显示我们的webservice请求
<%
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
Else
ASPNETResources = GetASPNetResources()
Application.Lock
Application("ASPNETResourcesUpdated")=Now()
Application("ASPNETResourceList")=ASPNETResources
Application.UnLock
End if
Response.Write Application("ASPNETResourceList")
%>
现在是神秘的i_soapcall.asp
大家在想神秘的GetASPNetResources()到底是什么样子的,可以用基本的asp页面调用webservice,不要忘了soap service无论是wsdl文档还是执行结果都是一个xml文档,所以我们可以parse(解析)它,这并不困难!
在函数中我们用到两个object
Function GetASPNetResources()
Set SoapRequest = Server.CreateObject("MSXML2.XMLHTTP")
Set myXML =Server.CreateObject("MSXML.DOMDocument")
SoapRequest 是服务器端组件,可以发送post和get请求。
myXML将被用来创建一个soap service的xml文档
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
我们设定SoapURL 为我们的webservice的url然后我们用下面的语句打开连接SoapRequest.Open "GET",SoapURL , False
SoapRequest.Open有五个参数,但是只有前两个是必需的,这意味着其他三个是可以随意选择的
参数解释:
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 be 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 is ignored if the user parameter is Null or missing
设置完毕我们用SoapRequest.Send()向服务器发送请求,服务器返回的结果作为文本被存储在SoapRequest.responseXML中。我们要做的就是构析这段文本。
下面给出i_soapcall.asp的全部代码
同样的创作思路可以用在别的编程语言中
订阅本站,阅读更多文章