title: WCF:Failed to add a service. Service metadata may not be accessible
body: <p>I have searched this question , and got too many links ,and tried most of them , but my problem is not solved . I'm running my VS in admin mode.
  I created new project then add WCF service to my project .I want to call my service through ajax.</p>
  
  <p>this is my code in Sevice.cs and Iservice.cs</p>
  
  <pre><code>namespace WcfWithAjax
  {
      [ServiceContract]
      public interface IService
      {
          [OperationContract]
          [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
          string GetEmployeeList();
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>namespace WcfWithAjax
  {
  
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class Service : IService
      {
          [OperationContract]
  
          public string GetEmployeeList()
          {
              string str = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
              IList&lt;Employee&gt; employeeList = new List&lt;Employee&gt;();
              using (SqlConnection con = new SqlConnection(str))
              {
                  con.Open();
                  SqlCommand cmd = new SqlCommand("select * from Employee", con);
                  SqlDataReader dr = cmd.ExecuteReader();
                  while (dr.Read())
                  {
                      employeeList.Add(new Employee()
                      {
                          Id = dr.GetInt32(0),
                          Name = dr.GetString(1),
                          Position = dr.GetString(2),
                          Age = dr.GetInt32(3),
                          Salary = dr.GetInt32(4)
                      });
                  }
                  con.Close();
              }
              JavaScriptSerializer objJson = new JavaScriptSerializer();
              return objJson.Serialize(employeeList);
          }
  
      }
  }
  </code></pre>
  
  <p>and then configured my web.config file 
  as follow</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="metadataBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
  
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"
        multipleSiteBindingsEnabled="true" /&gt;
      &lt;services&gt;
        &lt;service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior"&gt;
          &lt;endpoint address=""  binding="webHttpBinding" contract="WcfWithAjax.IService" /&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>now I'm Debuging my project but it's showing </p>
  
  <p><strong>Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata</strong>.</p>
  
  <p>Here is some link i got but unable to solve my problem</p>
  
  <p><a href="https://stackoverflow.com/questions/5199541/failed-to-add-a-service-service-metadata-may-not-be-accessible-make-sure-your">failed-to-add-a-service-service-metadata-may-not-be-accessible-make-sure-your</a></p>
  
  <p><a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/4723024c-f41d-4190-ad02-4d943c970a05/wcf-failed-to-add-a-service-service-metadata-may-not-be-accessible?forum=wcf" rel="nofollow noreferrer">Link 2</a></p>