tags:

views:

1257

answers:

1

I am having an issue with writing a file to the response object. The file is Base64 encoded and is being sent to the ASP code via a web service.

dim contentType, fileName

filename = request("FileName")
contentType = request("ContentType")
If Not Response.isClientConnected Then
    Response.end
End If
Response.buffer = true
Response.Clear
Response.Addheader "Content-Disposition", "attachment; filename=" & filename
Response.contenttype = contentType

dim oSoapClient
Set oSoapClient = Server.CreateObject("MSSOAP.SoapClient")
oSoapClient.ClientProperty("ServerHTTPRequest") = True
oSoapClient.mssoapinit "http://myWS/test.asmx?WSDL"
dim sRequest, sResponse
sRequest = "<Root><Attachment id=""" & Request("ID") & """/></Root>"          
sResponse = oSoapClient.GetAttachment(sRequest)  
Dim oXML: Set oXML = LoadXMLString(sResponse)

Dim oAttachment
set oAttachment = oXML.SelectSingleNode("/Root/Attachment")
if not oAttachment is nothing then
    Response.Binarywrite(Base64Decode(oAttachment.attributes.getNamedItem("BinaryData").value))

End if
Response.End

The BinaryWrite is adding extra null characters every other byte. Change it to response.write and it does not put the nulls but terminates the string if a null character is found.

I'm looking for a method to use the binarywrite without it adding the extra nulls. Is it a charset issue?

Thanks

A: 

BinaryWrite is doing the correct thing here. What is the return type for your Base64Decode function? Extra null characters between every byte are a symptom of improper handling of UTF-16/UCS-16 unicode data.

Ideally, you should send a VARIANT to BinaryWrite that represents an object exposing IStream, or a SAFEARRAY. If you send in a VARIANT that is a string, it will be received by BinaryWrite as a BSTR, which is 16 bits wide and will exhibit nulls/zeroes every other byte for english/latin charset data.

meklarian