Solved

VBScript Calling web service

Posted on 2011-09-06
3
459 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

18 Experts available now in Live!

Get 1:1 Help Now