Solved

Issue calling a Web Service from Outlook Receive Return Code 500

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
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 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: …

803 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