azure - Unable to read message from Service bus. it is returning null -


i trying read stream on azure service bus. getting null bytes. file size getting created same size of bytes being sent, contains nulls. have added code used converting stream byte array function name readallbytes(stream source)

below code reference:

         static void main(string[] args)          {             memorystream largemessagestream = new memorystream();             #region receivemessage               var msg = microsoft.servicebus.namespacemanager.createfromconnectionstring(configurationsettings.appsettings["microsoft.servicebus.connectionstring"].tostring());             var numofmessages = msg.getqueue(accountdetails.queuename).messagecountdetails.activemessagecount.tostring();             if (msg.getqueue(accountdetails.queuename).requiressession)             {                 var queueclient1 = queueclient.createfromconnectionstring(configurationsettings.appsettings["microsoft.servicebus.connectionstring"].tostring(), accountdetails.queuename);                 var session = queueclient1.acceptmessagesession();                  console.writeline("message session id: " + session.sessionid);                 console.write("receiving sub messages");                  while (true)                 {                     // receive sub message                     brokeredmessage submessage = session.receive(timespan.fromseconds(5));                      if (submessage != null)                     {                         // copy sub message body large message stream.                         stream submessagestream = submessage.getbody<stream>();                         submessagestream.copyto(largemessagestream);                         // mark message complete.                         submessage.complete();                         console.write(".");                     }                     else                     {                         // last message in sequence our completeness criteria.                         console.writeline("done!");                         break;                     }                 }                  // create aggregated message large message stream.                 brokeredmessage largemessage = new brokeredmessage(largemessagestream, true);                  console.writeline("received message");                 console.writeline("message body size: " + largemessagestream.length);                  string testfile = @"d:\dev\csvdata1.csv";                 console.writeline("saving file: " + testfile);                  // save message body file.                 stream resultstream = largemessage.getbody<stream>();                 byte[] x = readallbytes(resultstream);                  file.writeallbytes(testfile, x);             }       public static byte[] readallbytes(stream source)     {         long originalposition = source.position;         source.position = 0;          try         {             byte[] readbuffer = new byte[source.length];             int totalbytesread = 0;             int bytesread;             while ((bytesread = source.read(readbuffer, totalbytesread, readbuffer.length - totalbytesread)) > 0)             {                 totalbytesread += bytesread;                 if (totalbytesread == readbuffer.length)                 {                     int nextbyte = source.readbyte();                     if (nextbyte != -1)                     {                         byte[] temp = new byte[readbuffer.length * 2];                         buffer.blockcopy(readbuffer, 0, temp, 0, readbuffer.length);                         buffer.setbyte(temp, totalbytesread, (byte)nextbyte);                         readbuffer = temp;                         totalbytesread++;                     }                 }             }              byte[] buffer = readbuffer;             if (readbuffer.length != totalbytesread)             {                 buffer = new byte[totalbytesread];                 buffer.blockcopy(readbuffer, 0, buffer, 0, totalbytesread);             }             return buffer;         }                 {             source.position = originalposition;         }     } 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -