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

458 views Asked by At

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.

2

There are 2 answers

1
Lionia Vasilev On BEST ANSWER

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.

6
BozoJoe On

If you are using .net 4.5 then you can use the simplified configuration style WCF bindings. this lets you configure a particular binding type and then when your client or service uses that particular binding type (say basicHttpBinding) the modified configuration will be used.

to modify the deafult binding, just don't specific a name.

so

<bindings> <basicHttpBinding> <binding messageEncoding="Mtom" /> </<basicHttpBinding> </bindings>

Now if you create a service using the basicHttpBinding, it will use Mtom rather than Text.