title: Could not find default endpoint element that references contract
body: <p>I know this has been beaten to death, but I cannot get this to work as it should.
  I have a WCF service with several contracts.
  They all work fine when calling them directly e.g.    <a href="http://merlin.com/CompanyServices/CompanyWcfService.svc/Get_Document_Dates_Received/223278" rel="noreferrer">http://merlin.com/CompanyServices/CompanyWcfService.svc/Get_Document_Dates_Received/223278</a>
  I have used this WCF service successfully on InfoPath Forms and Nintex Workflows.
  Now I create a simple ASP.Net application, such as was done in <a href="http://www.webcodeexpert.com/2013/04/how-to-create-and-consume-wcf-services.html" rel="noreferrer">http://www.webcodeexpert.com/2013/04/how-to-create-and-consume-wcf-services.html</a>.
  I was able to add a service reference as described in the article.
  I added a button the form, and added the following code in the <code>Button1_Click</code> event:</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      ServiceReference1.CompanyWcfServiceClient x = new ServiceReference1.CompanyWcfServiceClient();
      var result = x.Get_Document_Dates_Received("223278");
  }
  </code></pre>
  
  <p>when I click on the button I get the error: </p>
  
  <blockquote>
    <p>"Could not find default endpoint element that references contract 'ServiceReference1.ICompanyWcfService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."</p>
  </blockquote>
  
  <p>So I tried adding the following to the web.config: (copied directly from the web.config file of the CompanyWcfService.</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;services&gt;
    &lt;service name="CompanyWcfServices.CompanyWcfService" behaviorConfiguration="ServiceBehavior"&gt;
      &lt;endpoint address="" binding="webHttpBinding" contract="CompanyWcfServices.ICompanyWcfService" behaviorConfiguration="webHttpEndpointBehavior" &gt;
        &lt;identity&gt;
          &lt;dns value="localhost"/&gt;
        &lt;/identity&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"&gt;                                                                
      &lt;/endpoint&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding&gt;
        &lt;security mode="None"&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;behaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name ="webHttpEndpointBehavior"&gt;
        &lt;webHttp helpEnabled ="true" faultExceptionEnabled="true" automaticFormatSelectionEnabled="true"/&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="ServiceBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
      &lt;/behavior&gt;
      &lt;behavior name=""&gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true"/&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>I get the same exact error, there has to be something else going on.</p>
  
  <p>I finally gave up and called the service like this:</p>
  
  <pre><code>HttpWebRequest request = WebRequest.Create(@"http://merlin/Companyservices/CompanyWcfService.svc/Get_Document_Dates_Received/223278") as HttpWebRequest;
  request.Credentials = CredentialCache.DefaultCredentials;
  HttpWebResponse response = null;
  
  var result = "";
  try
  {
      response = request.GetResponse() as HttpWebResponse;
      if (response.StatusCode == HttpStatusCode.OK)
      {
          using (Stream stream = response.GetResponseStream())
          {
              StreamReader reader = new StreamReader(stream, Encoding.UTF8);
              result = reader.ReadToEnd();
          }
      }
  }
  catch (Exception ex)
  {
      result = "";
  }
  </code></pre>
  
  <p>I have spent hours reading posts and most of them suggest to copy the config information to the web.config file.  This seems problematic to me (besides the fact that it doesn't seem to work).  What if I need to consume a third party WCF service?  Do I have to request the config information from the third party?  And Visa Versa, if I create a WCF service designed to be consumed by third parties, do I need to provide them the config file as well?</p>