title: how to call wcf restful service from fiddler by JSON request?
body: <p>I am new in wcf restful service. I couldn’t find the problem which was, why my wcf restful service give ‘bad request’. I use .NET 4.0.</p>
  
  <p><strong>My service is:</strong></p>
  
  <pre><code>[OperationContract(Name="Add")]
  [WebInvoke(UriTemplate = "test/", Method = "POST",
            ResponseFormat=WebMessageFormat.Json,
            RequestFormat=WebMessageFormat.Json )]
  public int Add(Number n1)
  {
      res = Convert.ToInt32(n1.Number1) + Convert.ToInt32(n1.Number2);
      return res;
  }
  </code></pre>
  
  <p><strong>Data are..</strong></p>
  
  <pre><code>[Serializable]
      public class Number
      {
          public int Number1 { get; set; }
          public int Number2 { get; set; }
      }
  </code></pre>
  
  <p>When I call from fiddler its return ‘HTTP/1.1 400 Bad Request’</p>
  
  <p><strong>My fiddler request header is:</strong></p>
  
  <pre><code>User-Agent: Fiddler
  Host: localhost:4217
  Content-Type: application/json; charset=utf-8
  </code></pre>
  
  <p><strong>And request body is:</strong></p>
  
  <pre><code>{"Number1":"7","Number2":"7"}
  </code></pre>
  
  <p><strong>And response header is:</strong></p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Server: ASP.NET Development Server/10.0.0.0
  Date: Sun, 14 Aug 2011 18:10:21 GMT
  X-AspNet-Version: 4.0.30319
  Content-Length: 5450
  Cache-Control: private
  Content-Type: text/html
  Connection: Close
  </code></pre>
  
  <p>But if I call this service by C# client program it is ok.</p>
  
  <p><strong>My client code is:</strong></p>
  
  <pre><code>uri = "http://localhost:4217/Service1.svc/";
  Number obj = new Number() { Number1 = 7, Number2 = 7 };
  using (HttpResponseMessage response = new HttpClient().Post(uri+"test/",
         HttpContentExtensions.CreateDataContract(obj)))
  {
      string res = response.Content.ReadAsString();
      return res.ToString();
  }
  </code></pre>
  
  <p>please help me........</p>
  
  <p>Thanks. </p>