?
Solved

Issue calling a Web Service from Outlook Receive Return Code 500

Posted on 2016-08-24
2
Medium Priority
?
49 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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