Well now, just when I think I'm done with this little project they throw me another curve...
I have two WCFs. One hosted in IIS and the other is in a self-hosted service on a different server.
A function in the self-hosted service returns a PDF in the form of Byte(). The WCF in IIS calls the function, then uses System.IO.FileStream to write the PDF to intepub. The aspx performs a callback, and the page is reloaded with a dynamic iFrame displaying the pdf. Works good enough for me, but not good enough for the boss.开发者_运维问答
Somehow, I have to get the second WCF to pass the PDF back to my ASP app WITHOUT saving it to disk.
I need something like:
iFrameControl.Attributes.Add("src", ServiceReference1.GetPDF_Byte())
Any way to do this?
Thanks in advance, Jason
If I understand you correctly, there is some action in the ASPX page which causes a call (possibly passing some parameter) to be made to the first service (WCF1, hosted in IIS), which in turn calls the second service (WCF2, from a different machine); WCF1 retrieves the PDF from WCF2, saves it locally in inetpub and returns the URL of the saved file; the callback call on the ASPX page then uses that URL to display the PDF on the iFrame.
A short answer: you can't use a service reference to do what you need (ServiceReference1.GetPDF_Byte()) - the "src" attribute for the control (or for any XML) needs to be a string, which in this case represents the URL of the resource which is the actual source for the control. You can, however, use WCF to implement that - a REST endpoint in the "raw" mode (http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx) can be used to return a PDF file.
You would change the structure of your application as follows: some action in the ASPX page causes it not to make a call to WCF1 directly, but to simply set the "src" property of the iFrame control to a call to a REST endpoint in WCF1. This call would take the parameters, and call WCF2 to retrieve the PDF file, and that call would return the PDF file directly (as a Stream). This way you don't incur the buffering cost that you would in your buffer solution (if many clients are requesting the page at the same time you may have some memory issues, and in this case you don't need to manage buffer lifetimes either).
Found it somewhere else in C and did a conversion, posting here just in case someone else needs it.
Answer: Create a new class (Globals.vb) to house a byte array that can be accessed from both pages, then create a new page and do a response.BinaryWrite your byte array in Page Load, and set the iFrame's src to the new (blank) page.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.BinaryWrite(Globals.PDF_Data.ToArray)
End Sub
精彩评论