title: How do I properly pass System.Net.NetworkCredential to WCF Client?
body: <p>I currently have client device that prompts the user for user/pass and creates a <code>System.Net.NetworkCredential</code> that is passed to a <em>WCF</em> Service.  This <em>WCF</em> Service then uses the credential to use on another external service.  </p>
  
  <p>The problem is that whenever I pass through the <code>System.Net.NetworkCredential</code> to the service it seems to lose the password field and so I never get it to authenticate with the external service. I've tested just passing in plain text/strings as user/pass and it works but feel like this is not great for security (although I do have HTTPS enabled for all traffic between the two services).</p>
  
  <p>Is there a way to pass these credentials to the service correctly?</p>
  
  <p>Here is some test code on the <em>WCF</em> service:</p>
  
  <pre><code>public string TestCred(System.Net.NetworkCredential c, string username, string pass)
  {
  
      cred = c;
      userName = username;
      passWord = pass;
      string s = cred.UserName + cred.Password + "end";
      return s;
  
  }
  </code></pre>
  
  <p>I have it return that string to test what is actually received at the Service side and the password is completely blank (the username makes it there ok).</p>
  
  <p>Here is the code I use on the <em>WCF</em> service to contact the external service:</p>
  
  <pre><code>externalService.Credentials =  new System.Net.NetworkCredential(cred.UserName, cred.Password, "domain");
  </code></pre>
  
  <p>This doesn't work since the cred.Password field is blank, also I've tried:</p>
  
  <pre><code>externalService.Credentials = cred;
  </code></pre>
  
  <p>Which also fails.  </p>
  
  <p>When I use the plain strings though it works great:</p>
  
  <pre><code>externalService.Credentials =  new System.Net.NetworkCredential(userName, passWord, "domain");
  </code></pre>
  
  <p>Any suggestions?  Since the connection between the client device-WCF and Service-External Service are all <em>HTTPS-SSL</em> required, it is slightly secure but I didn't feel great passing user/pass with strings.</p>