title: Configure endpoint programmatically
body: <p>First of, let me start by saying I have no experience of doing endpoint/networking type of stuff, so my question might seem a bit stupid, so please bear with me :)</p>
  
  <p>I am working on porting an App written for Windows Phone 7 onto Windows 8 (Metro app). In the original App, there was a ServicesReference.ClientConfig file which defined the URL, bindings and other bits for the App to connect to the server (addresses changed):</p>
  
  <pre><code>&lt;client&gt;
    &lt;endpoint address="https://someurl.com/userservice.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_UserServices"
          contract="UserApi.UserServices" name="User_Services" /&gt;
    &lt;endpoint address="https://someurel.com/dataservice.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataServices"
        contract="DataApi.DataServices" name="Data_Services" /&gt;
  </code></pre>
  
  <p>Also, in the WP7 project, there were already two "Service References" added (one for User Services and one for Data Services), with supporting Reference.cs generated files. When I tried adding the service references into the Win8 project (VS2012), it generated a blank reference.cs file, so I simply added the Reference.cs file from the WP7 project into the W8 project, and also copied the ServiceReferences.ClientConfig file into the W8 project (so in terms of directory structure, it looked identical to the WP7 project).
  I think these Reference.cs files are the ones which provide the interface for the contracts</p>
  
  <p>Now, when I run my W8 app, I get an error during the part where it needs access to the service:</p>
  
  <blockquote>
    <p>InvalidOperationException was unhandled by user code
    Could not find endpoint element with name
    'User_Services' and contract
    'UserApi.UserServices' 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.</p>
  </blockquote>
  
  <p>So I figured the App isn't using the ServicesReferces.ClientConfig file to pickup the endpoints and network adresses, or it wasn't finding the Reference.cs files which I have importes into the project. So, assuming first it is not finding the endpoints correctly through the ServicesReferences.ClientConfig file, is it possible to do the same in code? </p>
  
  <p>All I got so far is this:</p>
  
  <pre><code>BasicHttpBinding binding = new BasicHttpBinding();
  EndpointAddress endpoint = new EndpointAddress(new Uri("https://someurl.com/someservice.svc"));
  </code></pre>
  
  <p>but I don't how to take this further (I added this into App.xaml.cs)</p>
  
  <p>Hope the question makes sense. If there is any further information you need, please let me know and I will try to find out about it while I go and educate myself more on this endpoint business</p>
  
  <p>Thanks in advance</p>