title: How can I send a DataContract object as parameter for a WCF RESTFUL webservice?
body: <p>I am developing a WCF resful service which will be basically consumed from some mobile applications.
  Over the POST I am trying to send a DataContract object [actually I have to send a List of object] and another single id as string. My question is if it is possibly to define my function to accept DataContract object and the single string ?</p>
  
  <p>Following is my code :
  Interface declaration:</p>
  
  <pre><code>[ServiceContract]
      public interface IService1
      {
  
          [OperationContract]
          [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetDataUsingDataContract/{id}")]
          CompositeType GetDataUsingDataContract(string id, CompositeType composite );
  
  
      }
  
      [DataContract]
      public class CompositeType
      {
          bool boolValue = true;
          string stringValue = "Hello ";
  
          [DataMember]
          public bool BoolValue
          {
              get { return boolValue; }
              set { boolValue = value; }
          }
  
          [DataMember]
          public string StringValue
          {
              get { return stringValue; }
              set { stringValue = value; }
          }
      }
  </code></pre>
  
  <p>Actual definition of the function:</p>
  
  <pre><code>public CompositeType GetDataUsingDataContract(string id, CompositeType composite )
          {
  
              if (composite == null)
              {
                  throw new ArgumentNullException("composite");
              }
              if (composite .BoolValue)
              {
                  composite .StringValue += "- Suffix and the id is"+id;
              }
              return report;
          }
  </code></pre>
  
  <p>and the json object I am trying to send from Fiddler is </p>
  
  <pre><code>{"BoolValue":true,"StringValue":"sdfsdfsf"}
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xrtzt.jpg" alt="Fiddler snap when sending the request">
  <img src="https://i.stack.imgur.com/slfkc.jpg" alt="Fiddler snap of the output">
  Above are the snaps from the fiddler I am testing the service from.
  After couple of googling I have got the following link where the client actually uses webservice reference to get the DataContract type and serializes to json before sending as request body. But why then my test from Fiddler doesn't succeed ?!
  <a href="http://dotnetmentors.com/wcf/wcf-rest-service-to-get-or-post-json-data-and-retrieve-json-data-with-datacontract.aspx" rel="nofollow noreferrer">http://dotnetmentors.com/wcf/wcf-rest-service-to-get-or-post-json-data-and-retrieve-json-data-with-datacontract.aspx</a></p>
  
  <p>Can anybody please suggest anything ?</p>
  
  <p>The web.config is as bellow:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="JSONWebService.Service1" behaviorConfiguration="JSONWebService.Service1Behavior"&gt;
          &lt;endpoint address="../Service1.svc"
              binding="webHttpBinding"
              contract="JSONWebService.IService1"
              behaviorConfiguration="webBehaviour" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="JSONWebService.Service1Behavior"&gt;
  
            &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="webBehaviour"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>