title: How can I fix "the Enumeration constraint failed"?
body: <p>I've been following a Microsoft <a href="https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/create-an-ajax-wcf-asp-net-client" rel="nofollow noreferrer">tutorial</a>.  on setting up AJAX-enabled WCF services and accessing them with a client. However, despite following the tutorial exactly, the result will not display as it is supposed to due to errors. Specifically, the errors state that the Enumeration constraint failed, rendering the "name" and "contract" attributes invalid.</p>
  
  <p>The error appears to be originating from my <code>Web.config</code> file, as the error list only shows issues in that file. Below I have included the code from the file, as well as from the service I am trying to access.</p>
  
  <pre><code>//The service model segment of the configuration file.  
  &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="SandwichServices.Service1AspNetAjaxBehavior"&gt;
            &lt;enableWebScript /&gt;
          &lt;/behavior&gt;
          &lt;behavior name="SandwichServices.CostServiceAspNetAjaxBehavior"&gt;
            &lt;enableWebScript /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"
        multipleSiteBindingsEnabled="true" /&gt;
      &lt;services&gt;
        &lt;service name="SandwichServices.CostService"&gt;
          &lt;endpoint address="" behaviorConfiguration="SandwichServices.CostServiceAspNetAjaxBehavior"
            binding="webHttpBinding" contract="SandwichServices.CostService" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <pre><code>//The .svc.cs file for my service
  using System.ServiceModel;
  using System.ServiceModel.Activation;
  
  namespace SandwichServices
  {
      [ServiceContract]
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class CostService
      {
          [OperationContract]
          public double CostOfSandwiches(int quantity)
          {
              return 1.25 * quantity;
          }
      }
  }
  </code></pre>
  
  <p>The following error messages appear in the Web.config file:</p>
  
  <blockquote>
    <p>The
    'contract' attribute is invalid - The value
    'SandwichServices.CostService' is invalid according to its datatype
    'serviceContractType' - The Enumeration constraint failed." "The
    'name' attribute is invalid - The value 'SandwichServices.CostService'
    is invalid according to its datatype 'serviceNameType' - The
    Enumeration constraint failed.</p>
  </blockquote>