Solved

Issue calling a Web Service from Outlook Receive Return Code 500

Posted on 2016-08-24
2
31 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
2 Comments
 
LVL 17

Accepted Solution

by:
xtermie earned 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
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: …

705 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

20 Experts available now in Live!

Get 1:1 Help Now