title: C# Passing a byte array as a Get Parameter to a web service using HttpRequestMessage
body: <p>I need to call a webservice from a third party company to authorize my access. The flow works in this way. The third party app calls my api controller action passing a string parameter (token) which represents a Guid(client id). After that, I need to call their other service to check if that received "token" is still valid(authorized). The problem is that the second call requires me to send the guid as a byte array. I tried a lot but couldn't figure out how to send the Guid converted in a byte array as a Get parameter. Here is my code. This returns a Bad Request. </p>
  
  <pre><code>private async Task&lt;User&gt; VerifyTokenAsync(string token)
      {
          try
          {
              byte[] bytesToken = new Guid(token).ToByteArray();
  
              string serviceUrl = string.Format("http://third.party.RequestTokenAuthorization?token={0}", bytesToken);
  
              using (HttpClient client = new HttpClient())
              using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(serviceUrl)))
              using (HttpResponseMessage response = await client.SendAsync(request))
              {
                  if (response.StatusCode == HttpStatusCode.OK)
                  {
                      var stream = await response.Content.ReadAsStreamAsync();                        
                  }
                  else
                  {                        
                      //todo
                  }
              }
          }
          catch (Exception ex)
          {
              Log.SaveError(ex);
              return null;
          }
      }
  </code></pre>
  
  <p>The URL after adding the byte array looks like this:
  http://third.party/RequestTokenAuthorization?token=System.Byte[]</p>
  
  <p>Obs: I added the service as a ServiceReference in my project, and calling it using the client generated method works:</p>
  
  <pre><code>byte[] bytes = new Guid(token).ToByteArray();
  
  ServiceReference1.Client client = new ServiceReference1.Client();
  
  var response = client.RequestTokenAuthorization(bytes);
  </code></pre>
  
  <p>I'm not sure but since I'm working with a asp.net web api, it seems "wrong" to me adding service reference to my project.</p>
  
  <p>Thank you!</p>