Search code examples
wcfwcf-binding

How to configure proxy address for multiple WCF-bindings at once?


To configure for proxy setup in WCF, I can solve it like this:

<binding name="bindingName" proxyAddress="http://proxySomething">

This, however, needs to be copied into every binding you have. I wondered if there was a way to set this for all bindings in just one place. Something like:

<proxy address="http://proxySomething" forAllBindings="true"/>

Is there such a setting? I have tried searching, but could not find it.

Update 1: It should also be noted that I have multiple types of bindings (basicHttpBinding, customBinding, wsHttpBinding and webHttpBinding) and several named bindings for some of the types.


Solution

  • You can use defaultProxy element from network settings:

    <configuration>
      <system.net>
        <defaultProxy>
          <proxy proxyaddress="http://someproxy:8080"/>
        </defaultProxy>
      </system.net>
    </configuration>
    

    More details in Info Support blog post.

    Notice that this is a global proxy and it used by WebRequest instances too.