PDF、WCF 和 iFames

发布于 2024-11-07 07:44:59 字数 459 浏览 0 评论 0原文

现在,当我认为我已经完成了这个小项目时,他们给了我另一条曲线......

我有两个 WCF。一个托管在 IIS 中,另一个托管在另一台服务器上的自托管服务中。

自托管服务中的函数以 Byte() 形式返回 PDF。 IIS 中的 WCF 调用该函数,然后使用 System.IO.FileStream 将 PDF 写入 intepub。 aspx 执行回调,并使用显示 pdf 的动态 iFrame 重新加载页面。对我来说足够好,但对老板来说还不够好。

不知何故,我必须让第二个 WCF 将 PDF 传递回我的 ASP 应用程序,而不将其保存到磁盘。

我需要这样的东西:

iFrameControl.Attributes.Add("src", ServiceReference1.GetPDF_Byte())

有什么办法可以做到这一点吗?

提前致谢, 贾森

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北渚 2024-11-14 07:44:59

如果我理解正确的话,ASPX 页面中有一些操作会导致对第一个服务(WCF1,托管在 IIS 中)进行调用(可能传递一些参数),该调用又调用第二个服务(WCF2,来自不同的机器); WCF1 从 WCF2 检索 PDF,将其保存在本地 inetpub 中,并返回保存文件的 URL;然后,ASPX 页面上的回调调用使用该 URL 在 iF​​rame 上显示 PDF。

简短的回答:您不能使用服务引用来执行您需要的操作 (ServiceReference1.GetPDF_Byte()) - 控件(或任何 XML)的“src”属性需要是一个字符串,在本例中表示作为控件实际来源的资源的 URL。但是,您可以使用 WCF 来实现 - “原始”模式下的 REST 端点 (http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model -web.aspx) 可用于返回 PDF 文件。

您可以按如下方式更改应用程序的结构:ASPX 页面中的某些操作导致它不直接调用 WCF1,而是简单地将 iFrame 控件的“src”属性设置为对 REST 的调用WCF1 中的端点。此调用将获取参数,并调用 WCF2 来检索 PDF 文件,并且该调用将直接返回 PDF 文件(作为流)。这样,您就不会像在缓冲区解决方案中那样产生缓冲成本(如果许多客户端同时请求该页面,您可能会遇到一些内存问题,在这种情况下,您也不需要管理缓冲区生命周期) )。

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).

jJeQQOZ5 2024-11-14 07:44:59

在 C 的其他地方找到它并进行了转换,发布在这里以防其他人需要它。

答案:创建一个新类(Globals.vb)来容纳可以从两个页面访问的字节数组,然后创建一个新页面并执行响应。Binary在页面加载中写入您的字节数组,并将 iFrame 的 src 设置为新的(空白)页。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文