title: How to make my json WCF to work
body: <p>I have struggled a lot spent quiet a lot of time but unable to make it work, after spending hours now I am able to see the metadata but unable to successfully call the operation. below are the steps and code.</p>
  
  <ol>
  <li>Create WCF Service library project.</li>
  </ol>
  
  <p>Now code.</p>
  
  <p><strong>Service contract and DataContract</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.ServiceModel.Web;
  
  using System.Text;
  
  namespace JsonWCFTest
  {
      [ServiceContract]
      public interface IJsonService
      {
          [OperationContract]
          [WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare,UriTemplate = "data/{id}")]
          Product GetProduct(string id);
      }
  
      [DataContract(Name = "product")]
      public class Product
      {
          [DataMember(Name = "id")]
          public string Id { get; set; }
      }
  
  }
  </code></pre>
  
  <p><strong>Service.</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace JsonWCFTest
  {
      public class JsonService:IJsonService
      {
          public Product GetProduct(string id)
          {
              return new Product {Id = " you have entered " + id};
          }
      }
  }
  </code></pre>
  
  <p>web.config</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true"/&gt;
    &lt;/system.web&gt;  
    &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment&gt;
        &lt;serviceActivations&gt;
          &lt;add relativeAddress="service.svc" service="JsonWCFTest.JsonService"/&gt;
        &lt;/serviceActivations&gt;
      &lt;/serviceHostingEnvironment&gt;
      &lt;services&gt;
        &lt;service name="JsonWCFTest.JsonService" behaviorConfiguration="jsonTestServiceBehavior"&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
          &lt;endpoint address="jsonTestEndPoint" behaviorConfiguration="jsonTestEndPointBehavior" 
                    binding="webHttpBinding" contract="JsonWCFTest.IJsonService"/&gt;        
  
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;      
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="jsonTestServiceBehavior"&gt;       
            &lt;serviceMetadata httpGetEnabled="true"/&gt;       
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="jsonTestEndPointBehavior"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  
  &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;&lt;/startup&gt;&lt;/configuration&gt;
  </code></pre>
  
  <p>when I am using this url</p>
  
  <blockquote>
    <p><code>http://localhost/service.svc/data/1</code></p>
  </blockquote>
  
  <p>it is giving me this below error in internet explorer</p>
  
  <blockquote>
    <p>Server Error in '/' Application. The resource cannot be found.
    Description: HTTP 404. The resource you are looking for (or one of its
    dependencies) could have been removed, had its name changed, or is
    temporarily unavailable.  Please review the following URL and make
    sure that it is spelled correctly.</p>
    
    <p>Requested URL: /service.svc/data/1</p>
  </blockquote>