正 文

无需.net和专用组件实现用asp访问webservice


www.7dspace.com  更新日期:2005-9-28 2:11:21  七度空间


      可能,大多数的人认为我们需要运行asp.net或使用soap toolkit以访问webservice。但是这不是必需的,使用微软的xml parser我们同样可以利用传统的asp页面来访问webservice,下面我就展示给大家看一看!

      我将使用三个文件来实现我的展示。

      global.asa,当程序开始运行时,使用application变量

      i_soapcall.asp 一个包含文件,用以访问soap service

      default.asp 一个基本的asp文件,用以显示soap数据Global.asa

      当website运行时global.asa时刻都在运行,在application_onstart中我们加入application变量

<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" -->

      当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")
2页,页码:[1] [2] 

上一篇:XML Schema 中空值的表示
下一篇:调用.NET XML Web Services返回的数据集合的方法
作者:codeof.com  来源: ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐