I am developing a java client to use the WCF service below. Since the WCF service uses Stream technology, I also hope to use stream technology in java client code to reduce memory usage. Can anybody give me advice on how to write it? Thanks.
namespace TmpWcfStream { [MessageContract] public class InputMessage { [MessageHeader(MustUnderstand = true)] public string TranName { get; set; } [MessageBodyMember(Order=1)] public Stream FileData { get; set; } } [MessageContract] public class OutputMessage { [MessageBodyMember(Order = 100)] public bool Success { get; set; } [MessageBodyMember(Order = 200)] public string ErrorMsg { get; set; } } } namespace TmpWcfStream { public class UploadDataSvc : UploadSvcContract { private const int bufferLen = 4096; public OutputMessage UploadData(InputMessage msg) { OutputMessage outputMsg = new OutputMessage { ErrorMsg = string.Empty, Success = true }; try { Stream inputStream = msg.FileData; String filePath = @"C:\tmp\output.txt"; using (FileStream targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { byte[] buffer = new byte[bufferLen]; int count = 0; while ((count = inputStream.Read(buffer, 0, bufferLen)) > 0) { targetStream.Write(buffer, 0, count); } } inputStream.Close(); } catch(Exception e) { outputMsg.Success = false; outputMsg.ErrorMsg = e.ToString(); } return outputMsg; } }
java stream interop wcf
Leo yao
source share