Solved

Issue calling a Web Service from Outlook Receive Return Code 500

Posted on 2016-08-24
2
45 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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