title: Using ServiceStack and RabbitMQ to send a stream
body: <p>I am attempting to send a stream using RabbitMQ and Servicestack (v1.0.41 using .NET Core).</p>
  
  <p>My Request implements <code>ServiceStack.Web.IRequiresRequestStream</code>, and the stream property is set in the client, but when it gets to the server, the stream is <code>NULL</code>.</p>
  
  <p><strong>Complete Repo</strong><br>
  Server Code:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Threading.Tasks;
  using Funq;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Hosting.Server;
  using Microsoft.AspNetCore.Http;
  using Microsoft.AspNetCore.Http.Features;
  using Microsoft.Extensions.DependencyInjection;
  using ServiceStack;
  using ServiceStack.Messaging;
  using ServiceStack.RabbitMq;
  using ServiceStack.Web;
  
  namespace Server
  {
      class Program
      {
  
          public static void Main(string[] args)
          {
              IWebHost host = new WebHostBuilder()
                  .UseServer(new RabbitServer())
                  .UseStartup&lt;Startup&gt;()
                  .Build();
  
              host.Run();
          }
      }
  
      public class RabbitServer : IServer
      {
          public void Dispose(){}
  
          public void Start&lt;TContext&gt;(IHttpApplication&lt;TContext&gt; application){}
  
          public IFeatureCollection Features { get; } = new FeatureCollection();
      }
  
      public class Startup
      {
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddLogging();
          }
  
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              app.UseServiceStack((AppHostBase)Activator.CreateInstance&lt;AppHost&gt;());
              app.Run((RequestDelegate)(context =&gt; (Task)Task.FromResult&lt;int&gt;(0)));
          }
  
      }
  
      public class AppHost : AppHostBase
      {
          public AppHost()
              : base("My Test Service", typeof(MyService).GetAssembly())
          {
          }
  
          public override void Configure(Container container)
          {
              var mqServer = new RabbitMqServer("127.0.0.1");
              container.Register&lt;IMessageService&gt;(mqServer);
              mqServer.RegisterHandler&lt;HelloRequest&gt;(ExecuteMessage);
              mqServer.Start();
          }
      }
  
      public class MyService : Service
      {
          public HelloResponse Any(HelloRequest request)
          {
              Console.WriteLine($"Stream is null: {request.RequestStream == null}");
              return new HelloResponse { Counter = request.Counter };
  
          }
      }
  
      public class HelloRequest : IReturn&lt;HelloResponse&gt;, IRequiresRequestStream
      {
          public int Counter { get; set; }
  
          public Stream RequestStream { get; set; }
      }
  
      public class HelloResponse
      {
          public int Counter { get; set; }
      }
  }
  </code></pre>
  
  <p>Client Code:</p>
  
  <pre><code>using ServiceStack;
  using ServiceStack.Messaging;
  using ServiceStack.RabbitMq;
  using ServiceStack.Web;
  using System;
  using System.IO;
  using System.Text;
  
  namespace Client
  {
      class Program
      {
  
          static void Main(string[] args)
          {
              RabbitMqServer messageService = new RabbitMqServer("127.0.0.1");
              RabbitMqQueueClient mqClient = messageService.MessageFactory.CreateMessageQueueClient() as RabbitMqQueueClient;
              var responseQueueName = mqClient.GetTempQueueName();
              MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Hello World!")) { Position = 0 };
              HelloRequest request = new HelloRequest { Counter = 100, RequestStream = ms };  //Counter is just some arbitary extra data
              Guid messageId = Guid.NewGuid();
  
              mqClient.Publish(QueueNames&lt;HelloRequest&gt;.In, new Message&lt;HelloRequest&gt;(request) { ReplyTo = responseQueueName, Id = messageId });
          }
      }
  
      public class HelloRequest : IReturn&lt;HelloResponse&gt;, IRequiresRequestStream
      {
          public int Counter { get; set; }
          public Stream RequestStream { get; set; }
      }
  
      public class HelloResponse
      {
          public int Counter { get; set; }
      }
  }
  </code></pre>
  
  <p>Note: I realise I could just use a byte[] in my request object, but I would quite like to make use of the provided <code>IRequiresRequestStream</code> interface so I can switch back to using HTTP rather than AMQP in the future. </p>
  
  <p>I should also say, that I probably won't be using the RabbitMQ Client provided by servicestack, as I am writing custom logic to convert from HTTP to AMQP, so I will be building the rabbitMQ request manually - the code above just demonstrates the problem I am having in the simplest way possible.</p>
  
  <p>I'm going to assume that this won't just work out of the box with AMQP (as it does with HTTP) - so I was thinking that I need to do something like serialize the stream to a <code>byte[]</code> and include it in the RabbitMQ message and then populate the dto which ServiceStack magically re-hydrates on the Server. </p>
  
  <p>So two questions really...<br>
  1. Am I on the right track?<br>
  2. If so, how do I hook into the de-serialization code on the server so that I have access to the raw RabbitMQ message in order to convert my byte[] back to a stream and set the stream on my dto?</p>