title: WCF Error {"The username is not provided. Specify username in ClientCredentials."}
body: <p>I have a WCF webservice hosted in IIS. Here is the configuration of the same: </p>
  
  <p>When i try to consume this particular service (when added  as  a service reference) in my WinForms client, it throw this exception:</p>
  
  <blockquote>
    <p>The username is not provided. Specify username in ClientCredentials. </p>
  </blockquote>
  
  <p>But when i add the service as a "web reference", i can execute all the methods perfectly.</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="BasicHttpEndpointBinding"&gt;
            &lt;security mode="TransportCredentialOnly"&gt;
              &lt;transport clientCredentialType="Basic" /&gt;
              &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  
        &lt;services&gt;
          &lt;service behaviorConfiguration="EMSServiceBehavior"
                                 name="EMSService.EMSCRUD"&gt;
            &lt;endpoint address="" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpEndpointBinding"
            name="BasicHttpEndpoint" contract="EMSService.IEMSCRUD"&gt;
            &lt;/endpoint&gt;
          &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="EMSServiceBehavior"&gt;
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
            &lt;!--&lt;serviceCredentials&gt;
              &lt;windowsAuthentication allowAnonymousLogons="False" includeWindowsGroups="True"/&gt;
            &lt;/serviceCredentials&gt;--&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;protocolMapping&gt;
        &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
      &lt;/protocolMapping&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Code when added as a service reference:</p>
  
  <pre><code>        EE.EMSCRUDClient obj = new EE.EMSCRUDClient();
          obj.ClientCredentials.Windows.ClientCredential.UserName = "demo";
          obj.ClientCredentials.Windows.ClientCredential.Password = "demo";
          obj.ClientCredentials.Windows.ClientCredential.Domain = "demo";
          obj.somemethod(); //Error here
  </code></pre>
  
  <p>Code when added as a web reference:</p>
  
  <pre><code>        testEMService.EMSCRUD ob = new testEMService.EMSCRUD();
          ICredentials credentials = new NetworkCredential("user", "pass");
          ob.Credentials = credentials;
          ob.somemethod();//No error
  </code></pre>