title: Error: Cannot obtain Metadata; using WCF Test client, C#, and trying to implement webhttpbinding and json
body: <p>I'm getting the fabled <code>Error: Cannot obtain Metadata from...</code> message, particularly <code>http://localhost:1640/Service1.svc</code>  I've scoured stackoverflow and Google and, so far, none of it has helped.  I created a new product to dumb it down and it's still not working.  So I am here asking for help.</p>
  
  <p>I'm trying to setup a WCF Service that uses JSON, which means I need to use webhttpbinding, in C#.  When I use the WCF Test Client, I get the aforementioned metadata error.  I'm using Visual Studio Express 2010 and the target framework.  I've been at this for two days and cannot understand why or what is the problem.</p>
  
  <p>I would appreciate any help.  Thank you. </p>
  
  <p>Here is  my web.config file:</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="WcfService4.Service1"
          behaviorConfiguration="jsonRestDefault"&gt;
  
          &lt;endpoint 
                name="jsonRestEndpoint"
                behaviorConfiguration="RESTFriendly"
                binding="webHttpBinding"
                contract="IService1"
                address="http://localhost:1640/Service1.svc"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="jsonRestDefault"&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="RESTFriendly"&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>
  
  <p>Here is the IService1.cs file:</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 WcfService4
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
      [ServiceContract]
      public interface IService1
      {
          [OperationContract]
          [WebInvoke(
              Method = "GET", 
              UriTemplate = "players",
              RequestFormat = WebMessageFormat.Json,
              ResponseFormat = WebMessageFormat.Json,
              BodyStyle = WebMessageBodyStyle.Bare)]
          List&lt;Person&gt; GetPlayers();
      }
  
      // Use a data contract as illustrated in the sample below to add composite types to service operations.
      [DataContract]
      public class Person
      {
          [DataMember]
          public string FirstName { get; set; }
  
          [DataMember]
          public string LastName { get; set; }
  
          [DataMember]
          public int Age { get; set; }
  
          public Person(string firstName, string lastName, int age)
          {
              this.FirstName = firstName;
              this.LastName = lastName;
              this.Age = age;
          }
      }
  }
  </code></pre>
  
  <p>Here is the Service1.svc.cs file:</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;
  using System.Net;
  
  namespace WcfService4
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
      public class Service1 : IService1
      {
          public List&lt;Person&gt; GetPlayers()
          {
              List&lt;Person&gt; players = new List&lt;Person&gt;();
              players.Add(new Person ( "Peyton", "Manning", 35 ) );
              players.Add(new Person ( "Drew", "Brees", 31 ) );
              players.Add(new Person ( "Brett", "Favre", 38 ) );
  
              return players;
          }
      }
  }
  </code></pre>