将文件从 WCF 传递到 WCF

发布于 2024-11-06 04:08:32 字数 448 浏览 1 评论 0原文

我在一台服务器上有一个 pdf 文件,我需要传递到另一台服务器上。两者都发布了 WCF。

在“服务”服务器上,我有以下代码(感谢反理智!):

Function GetPDF(ByVal fileName as String) as FileStream

Return File.OpenRead(fileName);

End Function

但我不知道如何在“接收”服务器上实际写入文件。我一直在玩 System.IO,但运气不太好。我需要类似的东西:

Sub WritePDF()

System.IO.WriteFile(MyService.GetPDF("Test.pdf"), "C:\NewPDF.pdf")

End Sub

对此的任何想法将不胜感激!

谢谢, 贾森

I have a pdf on one server I need to pass on another server. Both have WCF's published to them.

On the 'serving' server, I have the following code (thanks antisanity!):

Function GetPDF(ByVal fileName as String) as FileStream

Return File.OpenRead(fileName);

End Function

But I have no idea how to actually write the file on my 'receiving' server. I've been playing with System.IO, but I'm not having much luck. I need something like:

Sub WritePDF()

System.IO.WriteFile(MyService.GetPDF("Test.pdf"), "C:\NewPDF.pdf")

End Sub

Any ideas on this would be greatly apprecaited!

Thanks,
Jason

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

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

发布评论

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

评论(1

葬花如无物 2024-11-13 04:08:32

我相信这就是您正在寻找的:

.Net 4:

Using fileStream As Stream = File.Create("C:\NewPDF.pdf")
    MyService.GetPDF("Test.pdf").CopyTo(fileStream)
End Using

.Net 2.0/3.5:

    Using fileStream As Stream = File.Create("C:\NewPDF.pdf")
        Using inputStream As Stream = MyService.GetPDF("Test.pdf")
            Dim buffer(1023) As Byte
            Dim count As Integer = buffer.Length

            Do
                count = inputStream.Read(buffer, 0, count)
                If count = 0 Then Exit Do
                fileStream.Write(buffer, 0, count)
            Loop
        End Using
    End Using

I believe this is what you're looking for:

.Net 4:

Using fileStream As Stream = File.Create("C:\NewPDF.pdf")
    MyService.GetPDF("Test.pdf").CopyTo(fileStream)
End Using

.Net 2.0/3.5:

    Using fileStream As Stream = File.Create("C:\NewPDF.pdf")
        Using inputStream As Stream = MyService.GetPDF("Test.pdf")
            Dim buffer(1023) As Byte
            Dim count As Integer = buffer.Length

            Do
                count = inputStream.Read(buffer, 0, count)
                If count = 0 Then Exit Do
                fileStream.Write(buffer, 0, count)
            Loop
        End Using
    End Using
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文