title: Connecting to an asmx webservice with WCF through a proxy
body: <p><strong>Sorry answer found while typing</strong>    </p>
  
  <p>I am trying to connect to an external webservice that requires username/password authentication through a proxy. I am using Visual Studio Express 2008 to generate a service reference</p>
  
  <ul>
  <li>I have connected to the same
  webservice using a web reference.We
  only had to set a larger timeout
  because it takes a long time to
  finish. </li>
  <li>I have connected to another
  webservice that does not require
  username/password authentication
  with a generated service reference
  and some settings to get it through
  the proxy. </li>
  </ul>
  
  <p>So my thought would be to
      take this reference, point it to the
      correct webservice and add
      authentication.</p>
  
  <p>The config I am using without security:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8" ?&gt;
      &lt;configuration&gt;
        &lt;system.net&gt;
          &lt;defaultProxy useDefaultCredentials="true"&gt;
            &lt;proxy bypassonlocal="False" proxyaddress="http://***.***.****:80" /&gt;
          &lt;/defaultProxy&gt;
        &lt;/system.net&gt;
          &lt;system.serviceModel&gt;
            &lt;bindings&gt;
              &lt;customBinding&gt;
                &lt;binding name="AreaWebServiceSoap12"&gt;
                  &lt;textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                      messageVersion="Soap12" writeEncoding="utf-8"&gt;
                    &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                  &lt;/textMessageEncoding&gt;            
                  &lt;httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                      maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                      bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                      keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                      realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                      useDefaultWebProxy="true" /&gt;            
                &lt;/binding&gt;
              &lt;/customBinding&gt;
            &lt;/bindings&gt;
            &lt;client&gt;
              &lt;endpoint address="http://www.****.*****.****.com/samplewebservice/service.asmx"
                      binding="customBinding" bindingConfiguration="AreaWebServiceSoap12"
                      contract="ServiceReference1.ServiceSoap" name="ServiceSoap" /&gt;
              &lt;/client&gt;
          &lt;/system.serviceModel&gt;
      &lt;/configuration&gt;
  </code></pre>
  
  <p>I have added te following code to my call for authentication:</p>
  
  <pre><code>static void Main(string[] args)
  {
    ServiceSoapClient s = new ServiceSoapClient();
    s.ClientCredentials.UserName.UserName = @"username";
    s.ClientCredentials.UserName.Password = @"password";
  
    Service.RawGpsData[] result = s.GetRawGpsData(0);
    Console.WriteLine(String.Format("done:{0}",result.Length));
    Console.ReadLine();
  }
  </code></pre>
  
  <p>Just using this setup gives an error as expected:</p>
  
  <p><em>The HTTP request is not authorized with client authentication scheme Anonymous. The authentication header from the server is received, is NTLM.</em></p>
  
  <p>Now I get lost and start trying silly things because I am just starting to use WCF.</p>
  
  <p>When I add the following section to the config</p>
  
  <pre><code> &lt;security authenticationMode="UserNameOverTransport"&gt;&lt;/security&gt;
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p><em>The binding CustomBinding.http: / / tempuri.org / for the contract AreaWebServiceSoap.AreaWebServices is configured with a verification mode for which a transport level with integrity and confidentiality is required. The transport can not provide integrity and confidentiality.</em></p>
  
  <p>Sorry, while typing this question I stumbled upon the answer myself. I still think people might be interested in this and all comments and thoughts are still welcome. So I will leave the question here and make it community and post the answer myself.</p>