好吧,这是我的.
在一台服务器上,托管在IIS中的WCF。这个程序为驻留在同一服务器(主要是db调用)的ASP.NET应用程序处理大量内容。在ASP应用程序中,有一个嵌入式iFrame,其中包含一个PDF文档查看器。
在另一台服务器上,WCF驻留在Windows服务中。这个程序处理来自第一个WCF的调用,并启动一个生成PDF文件的第三方文档程序。现在,我有一个虚拟PDF文件坐在C:\驱动器上玩。
我的任务是:在WCF #2中有一个函数,将PDF文档的副本返回给WCF #1,这将把它保存到本地ASP应用程序目录中,这样嵌入式查看器就可以将它显示给用户。
到目前为止,我已经尝试让WCF #2返回一个FileStream对象,但是没有任何进展。我想这在WCF的世界里是个很大的不-不(我是个菜鸟)。
我不知道如何做到这一点,我的大部分努力都是徒劳的。你怎么处理这件事?有没有人?
谢谢!
发布于 2011-05-11 22:59:32
让WCF2接受该PDF并将其作为字节数组返回:
// fs is your FileStream
byte[] Data = new byte[fs.Length];
fs.Read(Data,0,fs.Length);WCF1调用WCF2并读取字节数组,然后将其保存到磁盘。
FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(buff);
bw.Close(); 发布于 2011-05-11 23:15:29
谢谢,杰森--我也做了类似的事。我想我会为下一个家伙发邮件:
WCF 2:
Public Function GetPDF_Byte() As Byte() Implements IService1.GetPDF_Byte
Dim fs As New FileStream("C:\211LD.pdf", FileMode.Open, FileAccess.Read)
Dim ImageData As Byte() = New Byte(fs.Length - 1) {}
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
GetPDF_Byte = ImageData
End FunctionWCF #1调用#2并将文件写入磁盘:
Sub Main
Dim WCF As New ServiceReference1.Service1Client
Dim ByteData As Byte()
Dim oFileStream As System.IO.FileStream
ByteData = WCF.GetPDF_Byte
oFileStream = New System.IO.FileStream("C:\NewPDF.pdf", FileMode.Create)
oFileStream.Write(ByteData, 0, ByteData.Length)
oFileStream.Close()
End Sub希望能帮到别人!
https://stackoverflow.com/questions/5970730
复制相似问题