In WCF service I fill Stream according to this question like :
result.Stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(result.Stream);
foreach (string fileN in zipFiles)
{
byte[] fileBytes = File.ReadAllBytes(fileN);
writer.Write(BitConverter.GetBytes(fileBytes.Length), 0, 4);
writer.Write(fileBytes, 0, fileBytes.Length);
}
writer.Flush();
return result;
before this I was returning stream by this and everything works in service and client side:
result.Stream = new MemoryStream(File.ReadAllBytes(fileN));
Stream be MessageBodyMember
but nut now changed it to save all file in one stream.
and Test method in client side:
ExportClient export = new ExportClient("exportEndPoint");
ExportResult_C result = export.Export(source);
result.Stream.Position = 0;
//result.Stream.SaveToFile("d:\kkk.log");
BinaryReader reader = new BinaryReader(result.Stream, System.Text.Encoding.UTF8);
string pathToSave = string.Empty;
while (result.Stream.Position < result.Stream.Length)
{
int size = reader.ReadInt32();
byte[] data = reader.ReadBytes(size);
pathToSave = "D:\test" + new Random().Next(0, 2564586).ToString() + ".zip";
File.WriteAllBytes(pathToSave, data);
}
the endpoint address:
<endpoint address="net.tcp://localhost:2082/Exchange/Export.svc" binding="netTcpBinding" bindingConfiguration="largeSizeStreamTcp"
contract="xxx" name="exportEndPoint"/>
and binding configuration:
<netTcpBinding>
<binding openTimeout="00:00:03" maxReceivedMessageSize="2000000000" transferMode="Streamed" maxBufferSize="2000000000" >
<readerQuotas maxDepth="32" maxArrayLength="2000000000" maxStringContentLength="2000000000" />
<security mode="None" />
</binding>
<binding name="largeSizeStreamTcp" transferMode="Streamed" receiveTimeout="00:30:00" sendTimeout="00:30:00" openTimeout="00:00:01" maxReceivedMessageSize="2000000000" maxBufferSize="2000000000" >
<readerQuotas maxDepth="32" maxArrayLength="2000000000" maxStringContentLength="2000000000" />
<security mode="None" />
</binding>
</netTcpBinding>
<netNamedPipeBinding>
I believe endpoint and binding is correct as I was able to return one file stream and save it back but now there is no prob in service side but when it will get from client side, Stream got lost it's content,length,position.
this is really drive me up the wall!!!
does anyone know why this is occurred(in client side) ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…