Getting a BASE64'ed Adobe Acrobat PDF file out of a Soap Envelope with Classic ASP
UPDATE: Simon Fell caught me in the midst of evil, as he rightfully points out that when one bypasses a SOAP Stack and "does their own thing" as I have here, I must perform the SOAP Processing Rules. I've update the code below, changes in RED.
NOTE: In the interest of correctness, I've included namespace qualification in the NEW code.
A fellow emailed me wanting to get a PDF file out of a SOAP Envelope and write it directly out to the browser using Classic ASP. Here's the code I used:
Set m_Doc = Server.CreateObject("MSXML2.DOMDocument.4.0")
m_Doc.async = false
m_Doc.ValidateOnParse = false
'This could come from whereever, ADO, a file, another Web Service.
m_Doc.Load Server.MapPath(".") + "\\soapresponse.txt"
m_Doc.setProperty "SelectionNamespaces", "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:def='http://localhost/'"
'There's nothing that I DO understand, so if there's anything I must, I'm screwed.
Set oHeader = m_Doc.selectNodes("//soap:Envelope/soap:Header/*[@soap:mustUnderstand = '1']")
If (Not oHeader Is Nothing) Then
If (oHeader.Length > 0) Then
Response.Write("Crap! I can't continue! What to do?")
'Yes, it's a // XPath, but that's the LEAST of our problems before we get into microperf
Set oNode = m_Doc.selectSingleNode("//def:GetImageAsBase64Result")
'This is the Magic that makes it possible. Otherwise you'll get a string.
oNode.dataType = "bin.base64"
Response.AddHeader "Content-Disposition", "filename=whatever.pdf"
This is given a SOAP Response like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">