http://hanhead.tistory.com/entry/Class-implementation-for-using-webservices-in-ASP

http://www.codeproject.com/KB/asp/aspcallwebservice.aspx

Introduction

Recently, I tried to use for the first time a webservice from an ASP page and I really had problems, after hours I could access to my webservice from ASP with Microsoft.XMLHTTP, but the code was not very easy (if it is your first time), so I decided to package the implementation in a simple vbscript class with a few properties that allow to access to a webservice.

The page that use the vbscript class is:

<!--#include virtual="/webservice.asp"-->
<html>
<head>
<title>testws</title>
</head>
<body>
<%
    dim ws
 
    set ws = new webservice
    ws.url = "http://localhost/yourwebservice.asmx"
    ws.method = "MethodName"
    ws.parameters.Add "ParamName1",1
    ws.parameters.Add "ParamName2",300
    ws.parameters.Add "ParamNameN",500
 
    ws.execute
    response.Write ws.response
 
    set ws = nothing
%>
</body>
</html>

Like you can see, it is very simple to use; define the properties, call the execute method and the property responsewill return the information from webservice.

The class that implement the call to webservice is:

<%
option explicit
class WebService
  public Url
  public Method
  public Response
  public Parameters
 
  public function execute()
    dim xmlhttp
    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    xmlhttp.open "POST", Url & "/" & Method, false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.send Parameters.toString
    response = xmlhttp.responseText
    set xmlhttp = nothing
  end function
  Private Sub Class_Initialize()
    Set Parameters = new wsParameters
  End Sub
  Private Sub Class_Terminate()
    Set Parameters = Nothing
  End Sub
End class
class wsParameters
  public mCol
  public function toString()
    dim nItem
    dim buffer
    buffer = ""
    for nItem = 1 to Count
      buffer = buffer & Item(nItem).toString & "&"
    next
    if right(buffer,1)="&" then
      buffer = left(buffer,len(buffer)-1)
    end if
    toString = buffer 
  end function
  public sub Clear
    set mcol = nothing 
    Set mCol = CreateObject("Scripting.Dictionary") 
  end sub
  public sub Add(pKey,pValue)
    dim newParameter
  
    set newParameter = new wsParameter
    newParameter.Key = pKey
    newParameter.Value = pValue
    mCol.Add mCol.count+1, newParameter
  
    set newParameter = nothing
  end sub
  public function Item(nKey)
    set Item=mCol.Item(nKey)
  end function
  public function ExistsXKey(pKey)
    dim nItem
  
    for nItem = 1 to mcol.count
      if mCol.Item(nItem).key = pKey then
        ExistsXKeyword = true
        exit for
      end if
    next
  end function
  public sub Remove(nKey)
    mCol.Remove(nKey)
  end sub
  public function Count()
    Count=mCol.count
  end function
  Private Sub Class_Initialize()
    Set mCol = CreateObject("Scripting.Dictionary")
  End Sub
  Private Sub Class_Terminate()
    Set mCol = Nothing
  End Sub
end class
class wsParameter
   public Key
   public Value
   public function toString()
     toString = Key & "=" & Value
   end function
end class
%>

I hope that this small code of my implementation can help you, thanks, and if any question please send me an email.

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

asanoguera


Estudie computacion desde los 12 años, a los 18 ya estaba trabajando en una empresa que desarrollaba soluciones para clinicas y laboratorios bioquimicos en QuickBasic y BTrieve, a los 21 comence a trabajar en una consultora que desarrollaba soluciones a medida para empresas en QBX, VB5 y MSAccess, tambien me desempeñé como programador senior durante 5 años en un ente gubernamental realizando analisis y desarrollando sistemas de gestion y estadisticas para la toma de decisiones en VB6, ASP y MS-SQL 2000, independientemente desarrolle varios proyectos y trabaje tambien para empresas en el extranjero en ASP/ASP.NET y MS-SQL 2000, actualmente desarrollo aplicaciones web en ASP.NET 2.0, Atlas, con WebServices y MS-SQL 2000
Occupation: Web Developer
Location: Argentina Argentina

'asp' 카테고리의 다른 글

닷넷으로 작성해서 classic asp에서 사용하기.  (0) 2010.08.24
Calculate Distance and Radius in ASP  (0) 2010.08.24
generate GUID  (0) 2010.08.24
ASP JSON Utility  (0) 2010.08.24
ajaxed v 1.0  (0) 2010.08.24

+ Recent posts