Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a Binding configuration and a Behavior?

Tags:

.net

wcf

I'm trying to get WCF config files better so I can more-easily work on more-complex scenarios. As is usually the case, I'm revisiting my understanding of the basics. So this brings up the question, What is the difference between a Binding configuration and a Behavior? I'm not asking about what is a binding (i.e. netTcpBinding, etc.). I get that.

So let's say I have a config file with multiple configurations for that single binding:

  <netTcpBinding>
    <binding name="LargeMessages" maxBufferPoolSize="5242880" maxBufferSize="5242880" maxReceivedMessageSize="5242880">
      <readerQuotas maxDepth="256" maxStringContentLength="16384" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None"></security>
    </binding>
    <binding name="LargeFiles" maxBufferPoolSize="15728640" maxBufferSize="15728640" maxReceivedMessageSize="15728640">
      <!-- 15MB max size -->
      <readerQuotas maxDepth="256" maxStringContentLength="15728640" maxArrayLength="15728640" maxBytesPerRead="204800" maxNameTableCharCount="15728640" />
      <security mode="None"></security>
    </binding>
    <binding name="LargeStrings" maxBufferPoolSize="524288" maxBufferSize="524288" maxReceivedMessageSize="524288">
      <!-- 0.5MB max size -->
      <readerQuotas maxDepth="256" maxStringContentLength="524288" maxArrayLength="524288" maxBytesPerRead="204800" maxNameTableCharCount="524288" />
      <security mode="None"></security>
    </binding>
  </netTcpBinding>

In this scenario, I'm calling LargeMessages, LargeFiles, and LargeStrings "Binding Configurations".

Now that I have that config, I can also have multiple Behaviors, where one might look like this:

<behavior name="DefaultServiceBehavior">
  <serviceCredentials>
    <serviceCertificate findValue="1234123412341234123412341234"
                        x509FindType="FindByThumbprint" />
  </serviceCredentials>
  <serviceMetadata/>
  <serviceDebug includeExceptionDetailInFaults="true" />
</behavior>

In this case, DefaultServiceBehavior is a behavior.

So a different way to ask my question is, Why can't my Binding Configuration contain all of my settings that my Behavior specifies? Or vice versa? At a basic and high level, why do we have both sets of settings? It seems both can very significantly affect my transport configuration or my message configuration. I just don't see the logic for the separation of settings.

like image 463
Jaxidian Avatar asked Feb 04 '13 23:02

Jaxidian


1 Answers

In technical terms:

  • Bindings: are used to specify the transport, encoding, and protocol details required for clients and services to communicate with each other.
  • Behaviors: are types that modify or extend Service or Client functionality.

In layman's terms:

  • Bindings: are used to specify the language your service speaks (ex: English, Portuguese, etc). A service and a client can only communicate with each other if they agree to speak the same language.
  • Behaviours: are used to define how your service should act. For instance, British Queen's Guards are expected to stand perfectly still while on duty, because that's how protocol dictates they should act, otherwise people might doubt they are truly British guards.

Conclusion, your services should speak the appropriate language (binding) and act (behaviour) as they are supposed to otherwise clients might have a hard time trying to communicate with them.

like image 102
Thomas C. G. de Vilhena Avatar answered Sep 20 '22 12:09

Thomas C. G. de Vilhena