title: How to inject WCF service client in ASP.Net core?
body: <p>I have WCF service that I need to access from ASP.NET Core. I have installed <a href="https://visualstudiogallery.msdn.microsoft.com/c3b3666e-a928-4136-9346-22e30c949c08" rel="noreferrer">WCF Connected Preview</a> and created proxy successfully.</p>
  
  <p>It created interface &amp; client something like below</p>
  
  <pre><code>    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
      [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.IDocumentIntegration")]
      public interface IDocumentIntegration
      {
  
          [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IDocumentIntegration/SubmitDocument", ReplyAction="http://tempuri.org/IDocumentIntegration/SubmitDocumentResponse")]
          [System.ServiceModel.FaultContractAttribute(typeof(ServiceReference1.FaultDetail), Action="http://tempuri.org/IDocumentIntegration/SubmitDocumentFaultDetailFault", Name="FaultDetail", Namespace="http://schemas.datacontract.org/2004/07/MyCompany.Framework.Wcf")]
          System.Threading.Tasks.Task&lt;string&gt; SubmitDocumentAsync(string documentXml);
      }
  
      [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
      public interface IDocumentIntegrationChannel : ServiceReference1.IDocumentIntegration, System.ServiceModel.IClientChannel
      {
      }
  
      [System.Diagnostics.DebuggerStepThroughAttribute()]
      [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.3.0.0")]
      public partial class DocumentIntegrationClient : System.ServiceModel.ClientBase&lt;ServiceReference1.IDocumentIntegration&gt;, ServiceReference1.IDocumentIntegration
      { 
        // constructors and methods here
      }
  </code></pre>
  
  <p>The consumer class that calls the service looks like below</p>
  
  <pre><code>public class Consumer
  {
    private IDocumentIntegration _client;
    public Consumer(IDocumentIntegration client)
    {
      _client = client;
    }
  
    public async Task Process(string id)
    {  
       await _client.SubmitDocumentAsync(id);
    }
  } 
  </code></pre>
  
  <p>How do I register the IDocumentIntegration with ConfigureServices method in Startup class?
  I want to setup RemoteAddress &amp; clientCredentials during the registration</p>
  
  <pre><code>  public void ConfigureServices(IServiceCollection services)
      {
          services.AddApplicationInsightsTelemetry(Configuration);
          services.AddMvc();
  
          // how do I inject DocumentIntegrationClient here??
          var client = new DocumentIntegrationClient();            
          client.ClientCredentials.UserName.UserName = "myusername";
          client.ClientCredentials.UserName.Password = "password";
          client.Endpoint.Address = new EndpointAddress(urlbasedonenvironment)
  
      }
  </code></pre>