title: WCF and JSON binding
body: <p>I am trying to create a wcf service that returns json. I have some problems with my config file and i also don't know how to test it.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="false" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="ContactLibraryJSON.ContactLibrary"&gt;
          &lt;endpoint address="" binding="webHttpBinding" bindingConfiguration="JSONEndpointBehavior"
            contract="ContactLibraryJSON.IContactServiceJSON" /&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
            contract="IMetadataExchange" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://192.168.1.31/ContactLibraryJSON" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="JSONEndpointBehavior"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
          &lt;behavior&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;/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>
  
  <p>I still get </p>
  
  <blockquote>
    <p>"Cannot add the behavior extension webhttp to the service behavior
    names <code>JSONEndpointBehavior</code> because the underlying behavior type does
    not implement the <code>IServiceBehaviorInterface</code>"</p>
  </blockquote>
  
  <p>Contact is defined like :</p>
  
  <pre><code>[DataContract(Name="Contact")]
  public class Contact
  {        
      [DataMember(Name="FirstName")]
      public string firstName=null;
      [DataMember(Name="LastName")]
      public string lastName=null;
      [DataMember(Name="Email")]
      public string email=null;
      [DataMember(Name = "Age")]
      public int age = 0;
      [DataMember(Name = "Street")]
      public string street=null;
      [DataMember(Name = "City")]
      public string city=null;
      [DataMember(Name = "Country")]
      public string country=null;
  }
  </code></pre>
  
  <p>IContactService is defined like :</p>
  
  <pre><code>[ServiceContract]
  public interface IContactServiceJSON
  {
      [OperationContract]
      [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")]
      Contact GetContact();        
  }
  </code></pre>
  
  <p>The implementation of <code>GetContact</code>:</p>
  
  <pre><code>public Contact GetContact()
  {
      return new Contact()
      {
          firstName = "primulNume",
          lastName = "alDoileaNume",
          age = 33,
          city = "Cluj",
          country = "Romania",
          email = "ceva@mail.com",
          street = "Bizusa 8"
      };
  }
  </code></pre>
  
  <p>My service runs on another computer in my lan. Base address is like: <a href="http://192.168.1.xxx/ContactLibraryService" rel="nofollow">http://192.168.1.xxx/ContactLibraryService</a>. <code>ContactLibraryService</code> is hosted by IIS and is converted to an application. </p>