title: WCF, ChannelFactory, "Could not find endpoint element..."
body: <p>I'm trying to call a WCF service from within another service, in part using an example I found here on StackOverflow which implements <strong>ChannelFactory</strong>.</p>
  
  <p>I've created a separate console app project within my solution for testing (VS 2008, btw), </p>
  
  <pre><code>namespace MyService.Test
  {
      class Program
      {
          static void Main(string[] args)
          {
              MySolution.MyTestClient proxy = new MyTestClient();
  
              proxy = new MyTestClient();
              proxy.Endpoint.Address = new EndpointAddress("http://localhost:8723/MySolution/");
  
              // Instantiate a request object and assign values to its member variables.    
              MySolution.RemoteServiceMethod() theObject = new RemoteServiceMethod();            
              theObject.SomeProperty = "123";
              theObject.SomeOtherProperty = "alpha";
  
              Console.WriteLine("Calling the remote service method now...");
  
              try
              {
                  proxy.SubmitRemoteServiceRequest(proxy.theObject);
              }
              catch (FaultException&lt;MySolution.RequestException&gt; e)
              {
                  // exception code hereMySolution
              }
          }
      }
  }
  </code></pre>
  
  <p>This is from the local service's <strong>App.Config</strong> showing the endpoint:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
    &lt;client&gt;
     &lt;endpoint address="http://MyService/MyService.asmx"
       binding="basicHttpBinding" bindingConfiguration="ServiceSoap"
       contract="ServiceReference.ServiceSoap"
       name="ServiceSoap" /&gt;
    &lt;/client&gt;
    ...
   &lt;/system.serviceModel&gt;  
  </code></pre>
  
  <p>This is from the test project's own <strong>App.Config</strong>:</p>
  
  <pre><code> &lt;client&gt;
        &lt;endpoint address="http://localhost:8723/MyService"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceContract"
          contract="ServiceContract.IServiceContract" name="BasicHttpBinding_IServiceContract" /&gt;
   &lt;/client&gt;  
  </code></pre>
  
  <p>This is the method I've exposed in my local service, which in turn passes a request object to the remote service:</p>
  
  <pre><code>public ServiceContract.Response.ZZZ_Response SubmitRemoteServiceRequest(ServiceContract.Request.ZZZ_Request sc_TheirServiceRequest)
  {
       var factory = new ChannelFactory&lt;ServiceReference.ServiceSoap&gt;("ServiceSoap");
       var wcfClient = factory.CreateChannel();
       bool closedSuccessfully = false;
  
       // Instantiate a response object which I will return to the consumer.
       ServiceContract.Response.ZZZ_Response zzz_Response = new ServiceContract.Response.ZZZ_Response();
  
       // Instantiate request and response objects, respectively, which I use internal to my service to call remote service.
       ServiceReference.MyServiceRequest scMyServiceRequest = new ServiceReference.MyServiceRequest();
  
       ServiceReference.MyServiceResponse scMyServiceResponse = new ServiceReference.MyServiceResponse();
  
       try
       {                
            // Now you can make calls on the wcfClient object
            scMyServiceResponse = wcfClient.MyServiceMethod(scMyServiceRequest );                
  
            ((ICommunicationObject)wcfClient).Close();
            closedSuccessfully = true;
       }
       finally
       {
            if (!closedSuccessfully)
            {
                 ((ICommunicationObject)wcfClient).Abort();
            }
       }
  
       return zzz_Response;
  }
  </code></pre>
  
  <p>The error I receive is this:</p>
  
  <p><em>Could not find endpoint element with name '<strong>ServiceSoap</strong>' and contract '<strong>ServiceReference.ServiceSoap</strong>' 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 name could be found in the client element.</em></p>
  
  <hr />
  
  <p>I'm confused, where exactly am I missing the endpoint element, in the app.config for the local service (which has a Service Reference defined that points to the remote service), the app.config for the test app, or elsewhere?!</p>
  
  <hr />
  
  <p><strong>UPDATE</strong>: I found a workaround of sorts after reading <a href="http://msdn.microsoft.com/en-us/library/aa730857%28VS.80%29.aspx" rel="noreferrer">this MSDN article</a>, or I guess just a different way of instantiating the ChannelFactory:</p>
  
  <pre><code>var factory = new ChannelFactory&lt;ServiceReference.ServiceSoap&gt;(new BasicHttpBinding(), "http://urlToRemoteService/RemoteService.asmx");
  </code></pre>
  
  <p>Instead of trying to grab from nonexistent or incorrect info in my app.config, I'm instead manually plugging in the values for the Binding (BasicHttpBinding), and the address to the remote service. This seems to get me past the "Could not find endpoint element" error, but I'm not sure if this is the best solution.</p>