Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

VBScript Calling web service

I have a classic ASP page, inherited, that I need to call a web service that I created for another project in C# (Visusal Studio 2008).

My classic ASP page (a test page before I start working on the real page is the following):

</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">
<!--
<%
' this function taks an SQL statement and fills in the option values for a select box
' it also acceptes a selected value to use to check to select that value
' the SQL statment must have the option value = "as Value" and display = "as DisplayText
Function FillOptions(sSQL)
      set rsFun = (localhost.DataScriptService().DSNLoadDropDown(sSQL))
      
      %><option value="">--Select One--</option><%      
      
      If not rsFun.EOF Then
            Do while not rsFun.EOF                              
                  If trim(SelectedValue) = trim(rsFun("Input")) Then
                        %><option value="<%=trim(rsFun("Input"))%>" selected><%=trim(rsFun("Input"))%></option><%
                  Else
                        %><option value="<%=trim(rsFun("Input"))%>"><%=trim(rsFun("Input"))%></option><%
                  End If
                  
                  rsFun.MoveNext
 
            Loop
      End If 'checking for EOF
      
End Function
%>
-->

</SCRIPT>


<table id="FormTable" width="100%" border="0" style="display:none" style="BACKGROUND-COLOR:transparent">
      <tr>
            <td>

                  <SELECT name="SelectName" size="1">
                        <%                              
                              ' formatted select statement Value = value in the value caluse and
                              ' displayText = what is displayed in the select box
                              sSQL = "select ModalityName as Input from Modality"
                              ' function call from function above                        
                              FillOptions sSQL
                        %>      
                  </SELECT>
                  


            </td>
      </tr>
</table>


</BODY>
</HTML>

I am not sure what is suppose to go into:

      set rsFun = (localhost.DataScriptService().DSNLoadDropDown(sSQL))

I copied the code from a previous question that someone had answered for another experts exchange member.

I am assuming that the call to the service must go in here, but obviously I don't know what the correct syntax is suppose to be.

Any assistance would be greatly appreciated.

I went out and saw examples that deal with returning an XML file, but this service, which I have verified does indeed work, does not return an XML file.  It returns a string.

Thanks in advance.
0
Hawkeye6352
Asked:
Hawkeye6352
  • 2
1 Solution
 
strickddCommented:
To call a webservice in VBScript you have to use XML. The response will contain SOAP XML which needs to be parsed. Here is an example of how to do this, you will need to change the values according to your needs and setup.

Dim oXMLDoc, oXMLHTTP

Sub btnApproveLeave_Click

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

Set oXMLDoc = CreateObject("MSXML2.DOMDocument")

Msgbox("Calling WebService To Approve Leave")

oXMLHTTP.onreadystatechange = getRef("HandleStateChange")

call oXMLHTTP.open("POST","http://10.253.14.136/LeaveRequestWebService/CodeWebService.asmx/ApproveLeave",False)

call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")

call oXMLHTTP.send()

End Sub

 

Sub HandleStateChange

if(oXMLHTTP.readyState = 4) then

dim szResponse: szResponse = oXMLHTTP.responseText

call oXMLDoc.loadXML(szResponse)

if(oXMLDoc.parseError.errorCode <> 0) then

call msgbox(oXMLDoc.parseError.reason)

else

call msgbox(oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text)

end if

end if

End Sub

0
 
Hawkeye6352Author Commented:
I will give it a try and post back.
0
 
Hawkeye6352Author Commented:
I created a Web Method in a C# asmx (DSNLoadDropDown) that takes in a SQL statement, and returns the appropriate number of fields based on the input SQL and returns a string that can be parsed and processed accordingly.  I have tested this in C#, sending in SQL, and returning strings that I have processed accordingly.


However, the problem is, that the form is classic ASP.  So I have been working on a test classic ASP page to make a call and return data to it.  I am using the following code:

option explicit
dim oXMLDoc
dim oXMLHTTP
dim strEnvelope
dim strSQL
dim oXMLNodes

function ProcessSend()  
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
    msgbox"Ready state is " & oXMLHTTP.readyState


    oXMLHTTP.onreadystatechange = getRef("HandleStateChange")  
 
    'strEnvelope = "select ModalityName from Modality"
    strEnvelope = ""
    strSQL = "('select ModalityName from Modality')"
    msgbox"strSQL is " & strSQL

    call oXMLHTTP.open("POST","http://localhost/XXXX.TRUNK/Common/Services/DataScriptService.asmx?op=DSNLoadDropDown" & strSQL,false)'[[ changed true to false here.
    'call oXMLHTTP.open("POST","http://localhost/XXXX.TRUNK/Common/Services/DataScriptService.asmx?op=DSNLoadDropDown",false)'[[ changed true to false here.
   
    'call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
    call oXMLHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8")

 
    'call oXMLHTTP.send(strEnvelope)
    call oXMLHTTP.send()

    dim strResponseText
    dim strResponseXML
    dim strStatusText
    dim strStatus
    dim sHeaders
    dim strResponseBody

    strResponseText = oXMLHTTP.responseText
    msgbox"strResponseText " & strResponseText
    strStatusText = oXMLHTTP.statusText
    msgbox"strStatusText " & strStatusText
    strStatus = oXMLHTTP.status
    msgbox"strStatus " & strStatus
    sHeaders = oXMLHTTP.getAllResponseHeaders()
    msgbox"sHeaders " & sHeaders



end function
 
Sub HandleStateChange
    dim Root
    dim NodeList
    dim response
    dim Elem
    msgbox"Ready state inside HandleStateChange is " & oXMLHTTP.readyState
    if(oXMLHTTP.readyState = 4) then
        dim szResponse: szResponse = oXMLHTTP.responseText
        call oXMLDoc.loadXML(szResponse)
        if(oXMLDoc.parseError.errorCode [] 0) then
                msgbox"Ready state is " & oXMLHTTP.readyState
                msgbox"errorCode " & oXMLDoc.parseError.errorCode
                call msgbox("ERROR")
                response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
                call msgbox(oXMLDoc.parseError.reason)
        else
                msgbox"errorCode value in HandleStateChange else side  " & oXMLDoc.parseError.errorCode
                Set NodeList = oXMLDoc.getElementsByTagName("*")
                                For Each Elem In NodeList
                                                document.write(Elem.tagName)
                                Next

        end if
 
    end if
End Sub


If I use the call oXMLHTTP.send(strEnvelope) where strEnvelope contains the SQL, I get the following error returned:

the root level is invalid
 

If I use call oXMLHTTP.send() I get the following:

the root level is missing
 


The current issue is to make a call from a classic ASP page to the web service created in C# 2008.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now