title: WCF - Setting Policy for UsernameToken
body: <p>I received an updated WSDL for a service I'm consuming which has below Policy added</p>
  
  <pre><code>    &lt;wsp:Policy wssutil:Id="UsernameToken"&gt;
  &lt;ns0:SupportingTokens xmlns:ns0="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512"&gt;
   &lt;wsp:Policy&gt;
   &lt;ns0:UsernameToken ns0:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient"&gt;
   &lt;wsp:Policy&gt;
    &lt;ns0:WssUsernameToken10 /&gt; 
    &lt;/wsp:Policy&gt;
    &lt;/ns0:UsernameToken&gt;
    &lt;/wsp:Policy&gt;
    &lt;/ns0:SupportingTokens&gt;
    &lt;/wsp:Policy&gt;
  </code></pre>
  
  <p>I have updated my reference by right clicking the Service Reference --> Configure Service option inside Visual Studio.  This generated a customBinding replacing my previous basicHttpBinding</p>
  
  <pre><code>&lt;customBinding&gt;
              &lt;binding name="myBindingName"&gt;
                  &lt;!--    WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://ouaf.oracle.com/webservices/cm/CM-CustConnAcctDetailExtract':    --&gt;
                  &lt;!--    &lt;wsdl:binding name='CM-CustConnAcctDetailExtractSoapBinding'&gt;    --&gt;
                  &lt;!--        &lt;ns0:SupportingTokens xmlns:ns0="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512"&gt;..&lt;/ns0:SupportingTokens&gt;    --&gt;
                  &lt;textMessageEncoding messageVersion="Soap11" /&gt;
                  &lt;httpTransport /&gt;
              &lt;/binding&gt;
          &lt;/customBinding&gt;
  </code></pre>
  
  <p>Do I need to use this customBinding only? Or is there any option in basicBinding that makes it work?</p>
  
  <p>If I use my basicBinding with TransportWithMessageCredential, I get below error:</p>
  
  <blockquote>
    <p>The provided URI is Invalid; HTTPS is expected</p>
  </blockquote>
  
  <p>I ran this using SoapUI.  In addition to UserName and Passwrod, I had to supply <code>WSS-PasswordType</code> as <code>PasswordText</code>.  Without supplying this parameter, I get an error in SoapUI </p>
  
  <blockquote>
    <p>Error on verifying message against security policy Error code:1000</p>
  </blockquote>
  
  <p>I'm not sure how to supply WSS-PasswordType in my basicHttpBinding.</p>
  
  <p>My basicHttpBinding is as below</p>
  
  <pre><code>protected BasicHttpBinding GetBinding()
      {
          return new BasicHttpBinding()
                     {
                         Name = "BasicHttpBinding",
                         ReceiveTimeout = new TimeSpan(0, 0, 2, 0),
                         SendTimeout = new TimeSpan(0, 0, 2, 0),
                         Security =
                             {
                                 Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                                 Transport =
                                     {
                                         ClientCredentialType = HttpClientCredentialType.Basic,
                                         ProxyCredentialType = HttpProxyCredentialType.None,
                                         Realm = ""
                                     },
                                 Message =
                                     {
                                         ClientCredentialType = BasicHttpMessageCredentialType.UserName,
                                         AlgorithmSuite = SecurityAlgorithmSuite.Default
                                     }
                             },
                         MaxBufferSize = Int32.MaxValue,
                         MaxReceivedMessageSize = Int32.MaxValue,
                         ReaderQuotas = new XmlDictionaryReaderQuotas()
                         {
                             MaxBytesPerRead = 8192
                         }
                     };
      }
  </code></pre>