Search code examples
web-servicesvbscriptxmlhttprequest

How to call an exact method from web service using ASP/VBScript


I want to send data to the method SalePaymentRequest from this web service, but I don't know where to put the name of SalePaymentRequest method:

https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx

Here is my code in Classic ASP/VBScript:

amount = 1000
id = 1
pin = "mypincode"
posturl = "https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx"
backurl = "mywebsite/back.asp"

DataToSend = "LoginAccount=" & pin & "&Amount=" & amount & "&OrderId="& id & "&CallBackUrl="&backurl

Dim xmlhttp 
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", posturl, False
xmlhttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.Send DataToSend
Response.Write xmlhttp.ResponseText
Set xmlhttp = Nothing

Solution

  • By refering to the documentation of web service I found that the post should be a SOAP request and for accessing the SalePaymentRequest method, there is a SOPAction url introduced by service itself. I had to post SOAP to that URL. The format of SOAP document is totally defined by service documentation:

    pin = "mypincode"
    posturl = "https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx"
    backurl = "mywebsite/back.asp"
    '///This is the exact answer to my question! This URL defines the method target:
    SOAPAction ="https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService/SalePaymentRequest"
    
    soap="<?xml version=""1.0"" encoding=""utf-8""?>"
    soap=soap& "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
    soap=soap& "<soap:Body>"
    soap=soap& "<SalePaymentRequest xmlns=""https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService"">"
    soap=soap& "<requestData>"
    soap=soap& "<LoginAccount>" & pin & "</LoginAccount>"
    soap=soap& "<Amount>" & amount &"</Amount>"
    soap=soap& "<OrderId>"& id &"</OrderId>"
    soap=soap& "<CallBackUrl>"& backurl &"</CallBackUrl>"
    soap=soap& "</requestData>"
    soap=soap& "</SalePaymentRequest>"
    soap=soap& "</soap:Body>"
    soap=soap& "</soap:Envelope>"
    
    dim xmlhttp 
    set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "POST",posturl,false
    xmlhttp.setRequestHeader "Content-Type", "text/xml"
    xmlhttp.setRequestHeader "SOAPAction", SOAPAction
    
    xmlhttp.send soap
    Response.Write xmlhttp.responseText
    Set xmlhttp = nothing