Exchange 2007 Web Services Error with VBScript

Ok so I'm a VBScript guy and never learned .NET so that being said what I'm trying to do is connect to a particular mailbox and download attachments from any email in the inbox.  I've made some real good progress with the Exchange Web Services SOAP requests.  I can use the MSXML2.XMLHTTP object to POST to the URL of https://MAILSERVER/ews/exchange.asmx and I'm posting the XML listed in Microsofts documentation for certain functions  (http://msdn.microsoft.com/en-us/library/aa494316(v=exchg.140).aspx).  

I can view all the email in the inbox (FindItem), I can view the details of each email (GetItem) but I'm failing when I'm trying to get the details of the attachment from the email (GetAttachment).  The error message I'm getting is:

Server was unable to process request.  System.Xml.XmlException:  'xmlns' is an unexpected token.  Expecting white space.  Line 1, position 107.

I think this is saying the error is in the response but I can't see what the response text is so I have no idea what the error is.  My end goal is I'm simply trying to download the attachments (which will always be PDF's in my case) and I can only use VBScript.  Any help or direction would be GREATLY appreciated!  Here is my code:


const TARGETURL="https://MAILSERVER/ews/exchange.asmx"
const USERNAME="domain\username"
const PASSWORD="password"
GetAttachmentTemplate = "C:\GetAttachment.xml"

set fso=CreateObject("Scripting.FileSystemObject")

'---------------------------------------------------------
'	Read contents of GetAttachment.xml file
'---------------------------------------------------------
set oTS=fso.OpenTextFile(GetAttachmentTemplate)
sTemplate = ""
while not oTS.AtEndOfStream
	sTemplate=sTemplate & oTS.ReadLine
wend
oTS.Close


'---------------------------------------------------------
'	POST to Exchange Server for Attachment
'---------------------------------------------------------
set oXMLHTTP=CreateObject("MSXML2.XMLHTTP")
set oXML=CreateObject("MSXML2.DOMDocument")
	
oXMLHTTP.Open "POST", TARGETURL, false, USERNAME, PASSWORD
oXMLHTTP.SetRequestHeader "Content-Type", "text/xml"
oXMLHTTP.Send sTemplate
	
if oXMLHTTP.Status="200" then

	if oXML.LoadXML(oXMLHTTP.ResponseText) then
		set CreateItemResponse = oXML
		wscript.echo "It Worked"
	end if

else
	wscript.echo "It did NOT work.  Response status: " & oXMLHTTP.Status & VbCrLf & oXMLHTTP.StatusText & VbCrLf & oXMLHTTP.ResponseText
end if

Open in new window

LVL 2
tphelps19IT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tphelps19IT ManagerAuthor Commented:
Well I think I figured the answer out on my own.  I have no idea what  I did differently but the GetAttachment function now works and returns the attachment data in the <t:Content> element of the XML response.  That data is a MIME type data string but the problem is that it's encoded in base64 and since I'm running VBScript (which is 32bit) I have to use a base64 decoder.  I found a great one called XStandard Base64 Component.

BUT wait......not done yet.  So the other problem is I'm running this script on a 64bit server and the COM object (or dll file) from the link above is actually 32bit.  So even more fun.....I had to figure out how to run a 32bit COM object on a 64bit server.  Thanks to a helpful link on GFI's Webpage explaining how to do it by making a small registry tweak.  I figured it out but it wasn't the easiest instructions to follow so here are a little easier ones:

1)  Locate your COM object GUID under the HKey_Classes_Root\Wow6432Node\CLSID\[GUID]
      *Easiest way is to search for "XStandard" from the HKey_Classes_Root\Wow6432Node\CLSID\

2)  Once located add a new REG_SZ (string) Value.
      *Name is "AppID" (without quotes) and Data should be COM object GUID from step #1.
      *The GUID needs to include the "{" and "}" at the end.  ex: {118BAD5F-AB34-4140-9C78-0AB786C8A66D}

3)  Add a new key under HKey_Classes_Root\Wow6432Node\AppID\  and call it the same as the COM object GUID.
      *Again, make sure to include the "{" and "}"

4)  Under the new key you just added, add a new REG_SZ (string) Value, and call it "DllSurrogate" and leave the Value empty.

5)  Create a new Key under HKey_Local_Machine\Software\Classes\AppID\
      *Again the new key should be called the same as the COM object’s GUID.  Leave the Value empty.
      *If you get an error saying a key with that name already exists then you can skip this step, that happened to me for some reason.


That's it.  I was able to run the script anad all is well.  :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tphelps19IT ManagerAuthor Commented:
Kind of wished I got a little help though.......
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.