正 文

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


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


      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的全部代码

<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?"
    '这是真实可用的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>" &
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>

同样的创作思路可以用在别的编程语言中

2页,页码:[1]  [2] 

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

热 点 导 读
特 别 推 荐