How to access a web service using WCF 4.0 behind a proxy firewall

This one was causing my brain to melt…

In .NET 3.5, adding a Service Reference to a web service would automatically use the proxy server.  In .NET 4.0 something changed.  In 4.0, the call was failing with the error ‘The remote server returned an error: (407) Proxy Authentication Required.’  Trying to find the answer to this problem was a bit difficult as WCF 4.0 uses the term Proxy for the code proxies.  It took a bit, and the answer was dead simple…

Add the following code to the app.config or web.config file:

<system.net>
    <defaultProxy
      useDefaultCredentials="true">
    </defaultProxy>
</system.net>

This will tell .NET 4.0 to use the default credentials for the proxy server.

Doh!

Advertisements