[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Issue calling a Web Service from Outlook Receive Return Code 500

Posted on 2016-08-24
2
Medium Priority
?
58 Views
Last Modified: 2016-09-02
Receiving an error that the getRef object below cannot be found.  I am trying to call a web service from an Outlook macro.  The code snippet below is one I got online.  I did customize the code below to fit my environment.  Is there a library that I have to add for getRef?


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://localhost/WebService/CodeWebService.asmx/Leave",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

Open in new window



'''''''''''''''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


The following is code that I am using

Function ProcessSend()

 

Dim oXMLDoc, oXMLHTTP

Dim strEnvelope As String

 

Dim response As String

 

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

    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")

 

   '' strEnvelope = "sText=" & "test"

   strEnvelope = "test"

 

 

    Call oXMLHTTP.Open("POST", "mywebservicename.asmx?op=MyMethod", False)

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

    Call oXMLHTTP.Send(strEnvelope)

 

    Dim szResponse: szResponse = oXMLHTTP.responseText

    Call oXMLDoc.LoadXML(szResponse)

 

    If (oXMLDoc.parseError.ErrorCode <> 0) Then

        Call MsgBox("ERROR")

       '' response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason

        'call msgbox(oXMLDoc.parseError.reason)

    Else

       '' response = oXMLDoc.getElementsByTagName("string")(0).ChildNodes(0).Text

         MsgBox (oXMLHTTP.Status)

    End If

      

 

End Function

Open in new window

0
Comment
Question by:Member_2_7964962
[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 Comments
 
LVL 18

Accepted Solution

by:
xtermie earned 2000 total points
ID: 41769868
Could it be a problem of sequence/order (like calling before the library is loaded)?

Try this:
function ProcessSend() 
     Dim oXMLDoc, oXMLHTTP
     Dim strEnvelope As String
    Dim response As StringSet oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")

    strEnvelope = "test"

    call oXMLHTTP.open("POST", mywebservicename.asmx?op=MyMethod"&posFirm, false)
    call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
    call oXMLHTTP.send(strEnvelope)

    dim szResponse: szResponse = oXMLHTTP.responseText
    call oXMLDoc.loadXML(szResponse)

    if(oXMLDoc.parseError.errorCode <> 0) then
       'call msgbox("ERROR")
        'response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
        'call msgbox(oXMLDoc.parseError.reason)
    else
        'response = oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text
        MsgBox (oXMLHTTP.Status)
    end if
End Sub

Open in new window

0
 

Author Comment

by:Member_2_7964962
ID: 41780343
Thank you.
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.

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
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: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

650 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