private async Task OnBinaryMessageReceived(WebSocketHandler handler, byte[] bytes, string conversationId, string watermark) { int musicId = BitConverter.ToInt32(bytes, 0); int startIdx = BitConverter.ToInt32(bytes, sizeof(int)); Trace.TraceInformation(String.Format("get id {0}", musicId)); Trace.TraceInformation(String.Format("start from {0}", startIdx)); Uri uri = new Uri(baseURL + String.Format("{0}.wav", musicId)); CloudFile file = new CloudFile(uri, storageCredentials); Trace.TraceInformation(uri.AbsoluteUri); byte[] totalBytes = new byte[file.Properties.Length]; try { using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { ICancellableAsyncResult result = file.BeginDownloadRangeToByteArray(totalBytes, 0, null, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } Trace.TraceInformation(String.Format("File length {0}", totalBytes.Length)); totalBytes = totalBytes.Skip(startIdx).ToArray(); await handler.SendBinary(totalBytes, cts.Token); }