title: WCF post a byte[] to service?
body: <p>I'm trying to post a byte[] or FromBase64String string to my webservice. I keep getting the 404 error. I've changed the ["Content-type"] to "text/plain" and still get the error. However when I comment out the byteArray everything is fine. Does anyone have suggestions?</p>
  
  <p>Client:</p>
  
  <pre><code>      Object _object = new Object
          {
              Param1String = "data",
              Param2String= "data",           
              Param3String = "data",
              ByteArray = ReadAllBytes(@"C:\Folder\test.pdf")
          };
  
          try
          {
              WebClient Proxy = new WebClient();                
              Proxy.Headers["Content-type"] = "application/json";                
              MemoryStream stream = new MemoryStream();
              DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Object));
              serializer.WriteObject(stream, _object);
              byte[] data = Proxy.UploadData("http://localhost:4589/TestService.svc/FileUpload", "POST", stream.ToArray());
  
              stream = new MemoryStream(data);
              serializer = new DataContractJsonSerializer(typeof(Object));
              var result = serializer.ReadObject(stream) as Object;
              Console.WriteLine(result.Param1String);
              Console.ReadKey(true);
          }
          catch (Exception ex)
          {
  
          }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>    [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "/FileUpload")]
      void FileUpload(Patron patron);
  
      public void FileUpload(Object patron)
      {
  
              byte[] newBytes = null;
              BinaryWriter Writer = null;
              string Name = @"C:\\Temp\\" + object.Param1String + "";
              //byte[] bData = Helper.CopyToArray(object.ByteArray);
  
              try
              {
                  newBytes = Convert.FromBase64String(patron.ByteArray);
                  Writer = new BinaryWriter(File.OpenWrite(Name));                    
                  Writer.Write(newBytes);
                  Writer.Flush();
                  Writer.Close();
              }
              catch
              {                    
                  //return false;
              }
          }
  </code></pre>