title: How to manage byte[] params between applications with WebApi
body: <p>I have a controller (ApiController) which is ready to receive an XML as a parameter. One of its node is a byte[] (document) This service is built in .Net but another company is going to use my service from Java platform. </p>
  
  <p>We want to avoid that the service in .Net becomes blocked by receiving many request from Java application(this must be asynchronous) So the Java application can send us multiple request with the xml which contains the byte[] node. I don't know how the Java application must manage this call but in .net we want to continue being always available.</p>
  
  <p>I've been reading the new <strong>async</strong> and <strong>await</strong> keywords and I not very sure if it must apply to my service on my controller.</p>
  
  <p>My controller looks like this currently:</p>
  
  <pre><code>public class MyController : ApiController
  
      [HttpPost, ActionName("myMethod")]
      public void MyMethod(HttpRequestMessage request)
      {
          XmlDocument doc = new XmlDocument();
          doc.Load(request.Content.ReadAsStreamAsync().Result);
          //do something...
          //call method to transform byte[] to physical file and save it
      }
  </code></pre>
  
  <p>and I've been testing from another application (client) in .Net like this:</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          TestMethod();
      }
  
      public async Task TestMethod()
      {
          string xml = "&lt;root&gt; .......";
          var content = new StringContent(xml, Encoding.Unicode);
          var client = new HttpClient();
          HttpResponseMessage result = await client.PostAsync("http://localhost:port/api/myController/myMethod", content);
      }
  </code></pre>
  
  <p>It works fine. I mean click many times on the same button  and it creates my file correctly with a little delay (physically) because the file size but the client application it never gets blocked. But I'm not very sure if the client must run this asynchronously or the service must be prepared to do it by itself and the client from Java must only do the request through http.</p>
  
  <p>Or even, I must do the conversion of the file from byte[] to physical file async?</p>