Showing posts with label snippit. Show all posts
Showing posts with label snippit. Show all posts

Monday, March 26, 2012

Problem rendering to Excel when using SOAP

I'm using Reporting Services 2005 with VS2005 and getting garbage when setting format=excel. (snippit below) All the other formats work fine and excel works fine if I use URL access with the report manager for the same report.

Any ideas how to troubleshoot this? My SOAP code is as follows:

Dim reportAsByte() =NothingDim rsAs report_engine.ReportExecutionService =New report_engine.ReportExecutionService'credentials

rs.Credentials =

New System.Net.NetworkCredential("zzzzzzz","zzzzzzzzz","zzzzzzzzzzz")

rs.PreAuthenticate =

TrueDim reportpathAsString ="/" & System.Configuration.ConfigurationManager.AppSettings("report_folder") &"/" & report_nameDim zoomAsString ="False"Dim streamRootAsString =NothingDim deviceInfoAsString =NothingSelectCase formatCase"HTML4.0","HTML3.2"

deviceInfo =

"<DeviceInfo>"

deviceInfo &=

"<StreamRoot>" & streamRoot &"</StreamRoot>"

deviceInfo &=

"<Toolbar>False</Toolbar>"

deviceInfo &=

"<Parameters>False</Parameters>"

deviceInfo &=

"<HTMLFragment>True</HTMLFragment>"

deviceInfo &=

"<StyleStream>False</StyleStream>"

deviceInfo &=

"<Section>0</Section>"

deviceInfo &=

"<Zoom>" & zoom &"</Zoom>"

deviceInfo &=

"</DeviceInfo>"CaseElse

deviceInfo =

"<DeviceInfo></DeviceInfo>"EndSelect'variables for the remaining paramtersDim historyIDAsString =NothingDim credentialsAs report_engine.DataSourceCredentials =NothingDim showHideToggleAsString =NothingDim encodingAsStringDim mimeTypeAsStringDim warnings()As report_engine.Warning =NothingDim reportHistoryParameters()As report_engine.ParameterValue =NothingDim streamIDS()AsString =NothingDim execInfoAsNew report_engine.ExecutionInfoDim execHeaderAsNew report_engine.ExecutionHeader

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportpath, historyID)

Try'execute the report

report = rs.Render(Format, deviceInfo,

"", mimeType,"", warnings, streamIDS)'flush any pending response

Response.Clear()

'set the http headers for a PDF response

HttpContext.Current.Response.ClearHeaders()

HttpContext.Current.Response.ClearContent()

HttpContext.Current.Response.ContentType =

"text/html"'filename is the default filename displayed

HttpContext.Current.Response.AppendHeader(

"Content-Disposition","filename=""" & savefilename &"""")'send the byte array containing the report

HttpContext.Current.Response.BinaryWrite(report)

HttpContext.Current.Response.End()

Catch exAs ExceptionIf ex.Message ="Thread was being aborted."Then

HttpContext.Current.Response.ClearHeaders()

HttpContext.Current.Response.ClearContent()

HttpContext.Current.Response.ContentType =

"text/html"

HttpContext.Current.Response.Write(

"<HTML><body><h1>Error</h1><br>" & ex.Message &"</body></html>")EndIfEndTry

Here's the garbage that is generated:

? ? ?> ? ?????????????????????????????????????? !"#$%&'()*+,-./0123456789:;<=>?@.ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghi?????????ot Entry ?? `?# v??Workbook ? ??? ? ? ?? ? ?\p B ? a ?= ? ? ? = ??? X @. ? " ? ? 1 ?? Arial1 ?? Arial1 ?? Arial1 ?? Arial1 ? ? Arial1 @. ? Arial 3 "$"#,##0_);\("$"#,##0\) = "$"#,##0_);[Red]\("$"#,##0\) ? "$"#,##0.00_);\("$"#,##0.00\) I " "$"#,##0.00_);[Red]\("$"#,##0.00\) i*2 _("$"* #,##0_);_("$"* \(#,##0\);_("$"* "-"_);_(@._) W)) _(* #,##0_);_(* \(#,##0\);_(* "-"_);_(@._) y,: _("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@._) g+1 _(* #,##0.00_);_(* \(#,##0.00\);_(* "-"??_);_(@._) )? [$-1010409]General?? ????? ????? ????? ??????????????????????????????????? (?? +?? )?? ,?? *?? ?? `@.@.?? `@.?? ` @.?? `@.?? `@. @. ?? @.?? `@. @. ?? ` ?? `@. @. ?? `"" ?? `"" ?? `"" ? ? ? `"" ?? ? `"" ? ? `@. ?? `@. @. ? ? ` ?? ? ? ? ? ? ? ? ? ? ??0需 drugs_for_reordering? ? ??8 ? ?? ?? ?R ? 3????;s??? ?F ??3????;s????JFIF HH? (" & #0$&*+-.- "251,5(,-,? , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,? 0 " ? ? } !1A Qa "q 2? #B??R?$3br? %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz????????????????????????稩????? ? w !1 AQ aq "2? B??#3R??ъ $4? &'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??????????????????????妧詪???? ??E?? ?{?[??z.?e??? Z????????=?黄a??Y? ??w ??8?Μ ??z?qZ]???&o x??????? г??達??4????? ?a?M'? ы F? zWQ_5x UO x??\G K??仄? ?? ??8z?<?????? Q?fv8 Rk??? ?M?w???%#?o??'°xz?_k??X???B????f?K???d\??? ?Ty??????U Nk??h|*?a?

I solved my own issue. I was setting the headers wrong. Needed to change

HttpContext.Current.Response.ContentType =

"text/html"

to excel

sql