The size of the bytearray received to the client is different from that sent from the WCF service RRS feed

  • Question

  • I have a Self Hosted WCF service which is reading a big RAR file with binaryreader and returning bytearray to client

    Service splitting file as parts and 10MB per parts( 10485860 Bytes)

    I checking on debug mode for size of bytearray in WCF service before return and seeing 10485860 Bytes. So this is true size.

    But client received 13981237 Bytes per parts, why is this difference.

    This making my file is corrupt when i create clientside file with received bytes

    This is my code from WCF

     Dim i As Integer = 0
            my_InStream = New System.IO.FileStream("d:\temp\" + File, FileMode.Open, FileAccess.Read, FileShare.Read)
            Dim my_ibinaryreader As System.IO.BinaryReader = New System.IO.BinaryReader(my_InStream)
            Dim my_splitArr As New ArrayList
            'Dim ofile As FileInfo = New FileInfo(File)
            Dim ofilesize As Long = my_ibinaryreader.BaseStream.Length
            Dim partcount As Integer = ofilesize \ 10485860
            If ofilesize Mod 10485860 <> 0 Then partcount += 1
            my_ibinaryreader.BaseStream.Position = currentPartNumber * 10485860
            Dim myblocksize As Long = 0
            Dim my_bytearray() As Byte
            If currentPartNumber = partcount - 1 Then
                myblocksize = ofilesize - (currentPartNumber * 10485860)
                myblocksize = 10485860
            End If
            my_bytearray = my_ibinaryreader.ReadBytes(myblocksize)
            Return my_bytearray

    and This is my client code

    dim myReceivedByteArray as byte()

    dim partCount as integer = FileSize \ 104857600

    if FileSize mod 104857600 <> 0 then partCount += 1

    dim myWebClient as new WebClient

    for i as integer = 0 to partCount -1 myReceivedByteArray = myWebClient.DownloadData(string.format("SERVICEURL?file=bla.rar&currentPartNumber={0}",i))





    Thursday, July 18, 2019 7:43 AM

All replies