从WCF到WCF获取PDF [英] Getting a PDF from WCF to WCF

查看:112
本文介绍了从WCF到WCF获取PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我所拥有的...

Okay, here's what I have...

在一台服务器上,IIS中托管有WCF.这为驻留在同一服务器上的ASP.NET应用程序处理了很多东西(大多数是db调用).在ASP应用程序中,有一个嵌入式iFrame,其中包含PDF文档查看器.

On one server, a WCF hosted in IIS. This one handles a bunch of stuff for an ASP.NET application which resides on the same server (mostly db calls). In the ASP app, there's an embedded iFrame which contains a PDF document viewer.

在另一台服务器上,Windows服务中托管的WCF.这个程序处理来自第一个WCF的呼叫,并启动一个生成PDF文件的第三方文档程序.现在,我在C:\驱动器上有一个虚拟的PDF文件可以使用.

On another server, a WCF hosted in a Windows service. This one handles calls from the first WCF and kicks off a third-party document program which generates PDF files. For now, I have a dummy PDF file sitting on the C:\ drive to play with.

我的任务:要想在WCF#2中拥有某种功能,请将PDF文档的副本返回到WCF#1,它将保存到本地ASP应用程序目录中,以便嵌入式查看器可以将其显示给用户.

My mission: To somehow have a function in WCF #2 return a copy of the PDF document to WCF #1, which will save it to the local ASP application directory, so the embedded viewer can display it to a user.

到目前为止,我已经尝试过让WCF#2返回FileStream对象,但是那里没有运气.我想这是WCF世界中的一个大禁忌(我是菜鸟).

So far I've tried having WCF #2 return a FileStream object but no luck there. I guess that's a big no-no in the WCF world (I'm a noob).

我不知道如何实现这一目标,我的大部分努力都徒劳无功.您将如何处理?有人吗?

I have no idea how to accomplish this, most of my efforts are proving futile. How would YOU handle this? Anyone?

谢谢!

推荐答案

让WCF2获取PDF并将其作为字节数组返回:

Have WCF2 take the PDF and return it as a byte array:

   // fs is your FileStream
   byte[] Data = new byte[fs.Length];
   fs.Read(Data,0,fs.Length);

WCF1调用WCF2并读取字节数组,然后将其保存到磁盘

WCF1 calls WCF2 and reads the byte array, then saves it to disk

FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(buff);
bw.Close(); 

这篇关于从WCF到WCF获取PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆