title: WCF Restful post Services returns BAD REQUEST(400)
body: <p>I am trying from few days to consume wcf restful service but it is giving me bad reqeust. Please Help me out.</p>
  
  <p>Here is my configuration file</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name="state" allowCookies="true"&gt;
        &lt;security mode="None"&gt;&lt;/security&gt;
  
      &lt;/binding&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="ServiceBehaviour"&gt;
        &lt;serviceMetadata httpGetEnabled="True"/&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="True"/&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="web"&gt;
        &lt;webHttp/&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;services&gt;
    &lt;service behaviorConfiguration="ServiceBehaviour" name="RESTFUL_DEMO.Web.services.Calc"&gt;
      &lt;endpoint address="" bindingConfiguration="state" binding="webHttpBinding" name="Http" contract="RESTFUL_DEMO.Web.services.ICalc"/&gt;
      &lt;endpoint address="abcd" binding="wsHttpBinding" name="wsHttp" contract="RESTFUL_DEMO.Web.services.ICalc"/&gt;
  
      &lt;endpoint address="mex" binding="mexHttpBinding" name="MEX" contract="IMetadataExchange"/&gt;
  
    &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>
  
  <p></p>
  
  <p>my interface for service contract and datacontract is as follows.</p>
  
  <pre><code>[ServiceContract(SessionMode = SessionMode.Allowed)]
  [XmlSerializerFormat]
  public interface ICalc
  {
      [OperationContract]
      [WebInvoke(UriTemplate = "dowork", Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
      int DoWork(Enroll a);
  }
  
  
  [DataContract]
  public class Enroll
  {
      public Enroll()
      {
  
      }
      public Enroll(string Avalue)
      {
          this.Avalue = Avalue;
      }
      [DataMember(IsRequired = true)]
      public string Avalue
      {
          get;
          set;
      }
  
  
  }
  </code></pre>
  
  <p>my code to consume the service is as follows</p>
  
  <pre><code>HttpWebRequest request = WebRequest.Create("http://localhost/RESTFUL_DEMO.Web/services/Calc.svc/dowork") as HttpWebRequest;
  XmlDocument doc = new XmlDocument();
          doc.Load(@"d:\test.xml");
          string sXML = doc.InnerXml;
          request.ContentLength = sXML.Length;
          request.ContentType = "test/xml; charset=utf-8";
          var sw = new StreamWriter(request.GetRequestStream());
          sw.Write(sXML);
          sw.Close();
          WebResponse response = request.GetResponse();
          StreamReader stream = new StreamReader(response.GetResponseStream());
          String result = stream.ReadToEnd();
  </code></pre>