title: WCF Post / WebRequest Works - WebClient doesn't
body: <p>I have a WCF Service declared as follows:</p>
  
  <pre><code>[OperationContract, XmlSerializerFormat]
  [WebInvoke(UriTemplate = "ProessUpload",
     BodyStyle = WebMessageBodyStyle.Bare,
     RequestFormat = WebMessageFormat.Xml)]
  void ProcessUpload(ProductConfig stream);
  </code></pre>
  
  <p>I am trying to call this service using WebClient but I am always getting a response 400 (BadRequest) from the server. However if I use HttpWebRequest the WCF consumes my post and correctly responds with 200. I am also able to successfully construct a request using Fiddler to call the WCF Service.</p>
  
  <p>WebClient Code</p>
  
  <pre><code>WebClient webClient = new WebClient();
  webClient.Headers.Add("Content-Type", "application/xml");//; charset=utf-8
  try
  {
    string result = webClient.UploadString("http://jeff-laptop/SalesAssist.ImageService/Process", "POST", data2);
  }
    catch (Exception ex)
  {
    var e = ex.InnerException;
  }
  </code></pre>
  
  <p>HttpWebRequest code</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://jeff-laptop/SalesAssist.ImageService/Process");
  request.ContentType = "application/xml";
  request.Method = "POST";
  request.KeepAlive = true;
  
  using (Stream requestStream = request.GetRequestStream())
  {
    var bytes = Encoding.UTF8.GetBytes(data2);
    requestStream.Write(bytes, 0, bytes.Length);
    requestStream.Close();
  }
  
  var response = (HttpWebResponse)request.GetResponse();
  var abc = new StreamReader(response.GetResponseStream()).ReadToEnd();
  </code></pre>
  
  <p>The XML that is being sent</p>
  
  <pre><code>var data2 = @"&lt;Product&gt;&lt;Sku&gt;3327&lt;/Sku&gt;&lt;NameProduct&lt;/Name&gt;&lt;Category&gt;Bumper&lt;/Category&gt;&lt;Brand Id='3'&gt;&lt;Collection&gt;14&lt;/Collection&gt;&lt;/Brand&gt;&lt;/Product&gt;";
  </code></pre>
  
  <p>Why is that HttpWebRequest works and WebClient doesn't? I can't see a real difference in the sent headers via Fiddler.</p>