Solved

VBScript Calling web service

Posted on 2011-09-06
3
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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