Passing a file from WCF to WCF
I have a pdf on one server开发者_如何学JAVA 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
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
精彩评论