title: How to choose Soap client configuration from app.config using C#/UWP?
body: <p>I'm trying to put the Soap client configuration into the app.config. But I still face some problems.</p>
  
  <p>Here's my app.config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                  &lt;binding name="MyServiceHttpSoapBinding" maxReceivedMessageSize="20000000"&gt;
                      &lt;security mode="TransportCredentialOnly"&gt;
                          &lt;transport clientCredentialType="Basic" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
              &lt;/basicHttpBinding&gt;
              &lt;basicHttpsBinding&gt;
                  &lt;binding name="MyServiceHttpsSoapBinding" maxReceivedMessageSize="20000000"&gt;
                      &lt;security mode="Transport"&gt;
                          &lt;transport clientCredentialType="Basic" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
              &lt;/basicHttpsBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
              &lt;endpoint address="http://localhost:8080/webservice/MyService"
                  binding="basicHttpBinding" bindingConfiguration="MyServiceHttpSoapBinding"
                  contract="MyServiceReference.MyService" name="MyServiceHttpPort" /&gt;
              &lt;endpoint address="https://localhost:8080/webservice/MyService"
                  binding="basicHttpsBinding" bindingConfiguration="MyServiceHttpsSoapBinding"
                  contract="MyServiceReference.MyService" name="MyServiceHttpsPort" /&gt;
          &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And here's the code:</p>
  
  <pre><code>// init client
  MyServiceClient client = new MyServiceClient();
  client.ClientCredentials.UserName.UserName = uname;
  client.ClientCredentials.UserName.Password = pws;
  GetHelloServiceResponse response = await client.GetHelloService();
  // ...
  </code></pre>
  
  <p>With the debugger I found out that the client's endpoint's address is "<a href="http://localhost:8080/webservice/MyService" rel="nofollow noreferrer">http://localhost:8080/webservice/MyService</a>" and the binding is <em>basicHttpBinding</em>.
  But the Name is just "MyServicePort" not "MyServiceHttpPort" and the binding configuration "MyServiceHttpSoapBinding" is not used. So it doesn't work, because the binding's security settings are not set.</p>
  
  <p>I thought I could create the client with <code>new MyServiceClient("MyServiceHttpPort");</code>, but that constructor option is not available.</p>
  
  <p>Previously it worked with the coded configuration:</p>
  
  <pre><code>client.Endpoint.Address = new EndpointAddress(EndPoint);
  BasicHttpBinding binding = new BasicHttpBinding();
  binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
  binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
  client.Endpoint.Binding = binding;
  </code></pre>
  
  <p>But I'd prefer to do it by configuration.</p>