0 Replies - 983 Views - Last Post: 18 July 2019 - 03:55 AM Rate Topic: -----

#1 spider58   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-July 19

The size of the bytearray received from that WCF service is different

Posted 18 July 2019 - 03:55 AM

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 my_InStream As System.IO.FileStream = Nothing
        Try
            'Dim i As Integer = 0


            my_InStream = New System.IO.FileStream(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 \ 104857600

            If ofilesize Mod 104857600 <> 0 Then partcount += 1


            my_ibinaryreader.BaseStream.Position = currentPartNumber * 104857600
            Dim myblocksize As Long = 0
            Dim my_bytearray() As Byte

            If currentPartNumber = partcount - 1 Then
                myblocksize = ofilesize - (currentPartNumber * 104857600)
            Else
                myblocksize = 104857600
            End If

            my_bytearray = my_ibinaryreader.ReadBytes(myblocksize)
            my_ibinaryreader.Close()
            my_InStream.Close()
            Return my_bytearray

        Catch ex As Exception
            my_InStream.Close()
            Return Nothing
        End Try


And this code from Client

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ĪtPartNumber={0}",i))
      .
      .
      .
next



Is This A Good Question/Topic? 0
  • +

Page 1 of 1