Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoke Method from Web Service (SOAP)

Status
Not open for further replies.

uris20

Technical User
Nov 1, 2010
4
CO
I want to do a VBScript that invokes a method of a webservice and give a response depending the parameters of entry.

I have an example:
Code:
' VBScript source code
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-[URL unfurl="true"]www-form-urlencoded"[/URL]
    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
 
 
dim ws
 
'create web service object 
set ws = new webservice
'point it to CDYNE Phone Notify web service
ws.Url = "[URL unfurl="true"]http://ws.cdyne.com/NotifyWS/PhoneNotify.asmx"[/URL]
'we want to call this method
ws.Method = "NotifyPhoneEnglishBasic"
'fill parameters
ws.Parameters.Add "PhoneNumberToDial", 7573440000 '
ws.Parameters.Add "TextToSay","Hey, this is a test message"
ws.Parameters.Add "LicenseKey","0"
 
ws.execute

wScript.echo "Message: El resutaldo es: " &ws.Response
 
set ws = nothing

But the problem is that my web service does not show me the answer. Someone could tell me why?

Thanks,

Uris
 
Executing the script a window shows code html, ande says something like this:

"An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine
 
Executing the script a window shows code html, and says something like this:

"An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine
 
You have to uriencode the pkey and pvalue. As a quick fix, try this.

[tt]> [/tt]newParameter.Value = pValue
[tt] newParameter.Value = escape(pValue)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top