问题
I have a wevservice that returns an image as a Base64 string, or as a byte array, that I need to show as an image in SSRS. Not sure how to do that.
I tried using an expression in the image properties:
=System.Convert.FromBase64String("http://localhost:5460/api/Report/GetImage")
but that does not work. How do I get the string or array from the URL, then display it as an image?
I have also tried a Code block, but when I try
Dim hwr As System.Net.HttpWebRequest
hwr = System.Net.WebRequest.Create("http://localhost:5460/api/Report/GetImage")
I get the error:
Severity Code Description Project File Line Suppression State
Warning [rsRuntimeErrorInExpression] The Value expression for the textrun 'Textbox2.Paragraphs[0].TextRuns[0]' contains an error:
Insufficient permissions for setting the configuration property 'maximumErrorResponseLength'. (c:\program files (x86)\microsoft visual studio\2017\sql\common7\ide\commonextensions\microsoft\ssrs\PreviewProcessingService.exe.Config line 42) C:\Users\Desktop\REP90011\REP90011.rdl 0
This is on my local machine, not on the SSRS server or through IIS. Just through the preview pane in VS 2017.
回答1:
The problem was that I need to allow permissions in the file RSPreviewPolicy.config on my desktop to be 'FullTrust' instead of 'Nothing' in order to be able to use 'System.Net.WebRequest.Create'.
Edit: I have been asked to expand on how my process works, so here it is:
I have a webservice that fetches an image and returns it as a base64 string.
Put an image object on the report, set it to 'Database', 'image/bmp', and use this expression as the field:
=Convert.FromBase64String(Code.GetImageString("http://localhost:5460/api/Report/GetImage")
The URL being the webservice that returns the string.
The function GetImageString is in the Code section of report properties:
Public Function GetImageString(Url As String) As String
'create web request
Dim hwr As System.Net.HttpWebRequest
'this line is what I needed to change the permissions for
hwr = System.Net.WebRequest.Create(Url)
hwr .Credentials = System.Net.CredentialCache.DefaultCredentials
'get response from request
Dim wr As System.Net.WebResponse
wr = hwr.GetResponse()
'get stream from response
Dim sr as System.IO.Stream
sr = wr.GetResponseStream()
'read response stream
Dim read As IO.StreamReader
read = new IO.StreamReader(sr, System.Text.Encoding.UTF8)
'convert stream to string
Dim result as string
result = read.ReadToEnd
return result.substring(1, result.length - 2) 'remove first and last characters, it's putting in quotes
End Function
In VS 2017 this worked fine on my desktop. In VS 2019 it shows a red x on my desktop, but still works when deployed to the server.
来源:https://stackoverflow.com/questions/62093125/ssrs-show-base64-string-or-byte-array-from-url-as-image