Solved

VBScript Calling web service

Posted on 2011-09-06
3
462 Views
Last Modified: 2012-05-12
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
Comment
Question by:Hawkeye6352
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 250 total points
ID: 36496027
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
 

Author Comment

by:Hawkeye6352
ID: 36497997
I will give it a try and post back.
0
 

Author Comment

by:Hawkeye6352
ID: 36498274
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 56
Error viewing ASP page 12 146
ASP Button to clear text 4 43
Questions about INCLUDE FILES 2 17
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now