Yaron Naveh
Yaron Naveh

Reputation: 24406

WCF: How to get configuration from binding?

I have instantiated a WCF binding in code:

var binding = new WSHttpBinding();
binding.Secuity.Mode = SecurityMode.Transport;

Is there a way (in code) to get its equivalent configuration? For the above I would expect:

  <wsHttpBinding>
            <binding name="NewBinding0">
                <security mode="Transport" />
            </binding>
        </wsHttpBinding>

There is obviously a way to get the binding instance from config (every proxy needs that) so I am hoping the other direction is possible as well.

Upvotes: 1

Views: 917

Answers (2)

tomasr
tomasr

Reputation: 13849

You wouldn't be able to do this with an actual binding, but it might be possible if you create a BindingElement instead (WSHttpBindingElement), put it into a configuration section and then serialize the section into XML (this might help).

Remember that the binding object itself is not deserialized directly from the configuration XML. Instead, WCF has classes derived from ConfigurationElement for all config options and those will create the binding object itself later on.

Upvotes: 2

marc_s
marc_s

Reputation: 754458

No, I don't think there's any way to take a binding or another WCF element created in code and turn it into a configuration setting. Interesting idea and approach, but I don't think there's any way to do this right now, in WCF in .NET 3.5.

Marc

Upvotes: 1

Related Questions