Specifying behaviorConfiguration in codeIs there a way to set the behaviorConfiguration for a ServiceHost (or Client for that matter) in code?  All examples that I've seen show it being set in app.config.  I need the ability to define the behavior in the app.config, but then create the ServiceHost and endpoint objects entirely in code, passing to them the name of the config entry to use.<br><br>I do something similar now for the bindings.  I define the binding configurations in the app.config, but when I create the binding in code (for example wsHttpBinding), I use the overloaded constructor that allows me to pass in the string name of the entry in the app.config.  I'd like to do the same thing for services and clients.<br><br>Any ideas.<br><br>Thanks. <br><br>Bruce Bukovics<br>Author of .NET 2.0 Interoperability Recipes<br>http://www.apress.com/book/bookDisplay.html?bID=10116<br>© 2009 Microsoft Corporation. All rights reserved.Tue, 21 Oct 2008 19:41:27 Zd00d2a87-4d89-4510-9569-fab73a3ad070http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#d00d2a87-4d89-4510-9569-fab73a3ad070http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#d00d2a87-4d89-4510-9569-fab73a3ad070B Bukovicshttp://social.msdn.microsoft.com/Profile/en-US/?user=B%20BukovicsSpecifying behaviorConfiguration in codeIs there a way to set the behaviorConfiguration for a ServiceHost (or Client for that matter) in code?  All examples that I've seen show it being set in app.config.  I need the ability to define the behavior in the app.config, but then create the ServiceHost and endpoint objects entirely in code, passing to them the name of the config entry to use.<br><br>I do something similar now for the bindings.  I define the binding configurations in the app.config, but when I create the binding in code (for example wsHttpBinding), I use the overloaded constructor that allows me to pass in the string name of the entry in the app.config.  I'd like to do the same thing for services and clients.<br><br>Any ideas.<br><br>Thanks. <br><br>Bruce Bukovics<br>Author of .NET 2.0 Interoperability Recipes<br>http://www.apress.com/book/bookDisplay.html?bID=10116<br>Wed, 19 Jul 2006 20:53:10 Z2006-11-18T00:42:58Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#36130b91-2656-4b73-9e28-a88598e2b09ehttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#36130b91-2656-4b73-9e28-a88598e2b09eScott Mason - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Scott%20Mason%20-%20MSFTSpecifying behaviorConfiguration in code<p><font size=2>You can use the ServiceBehavior attribute with the <font size=2>ConfigurationName parameter.  Is that what you're looking for?</font></font></p> <p> </p> <p><font size=2>Thanks!</font></p> <p><font size=2>Scott</font></p>Wed, 19 Jul 2006 21:14:58 Z2006-11-15T20:30:34Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#ff8dc829-7257-4ea0-866f-298450164061http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#ff8dc829-7257-4ea0-866f-298450164061B Bukovicshttp://social.msdn.microsoft.com/Profile/en-US/?user=B%20BukovicsSpecifying behaviorConfiguration in codeNo, based on the documentation, it sounds like that specifies a name for the service.  I want to define several standard named behaviors (not services) in my app.config.  Then at runtime, I want to create my services in code (a ServiceHost) and tell them to lookup their behavior from one of the named behaviors in my app.config.  The WsHttpBinding (and others) allow me to do this using one of the overloaded constructors.  I'm looking for the same kind of thing for a service. <br><br>Thanks.<br><br>Bruce<br>Thu, 20 Jul 2006 12:18:19 Z2006-07-20T12:18:19Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#3d070aaf-d301-4022-9f67-2a8a12f29a22http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#3d070aaf-d301-4022-9f67-2a8a12f29a22Brian McNamara - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Brian%20McNamara%20-%20MSFTSpecifying behaviorConfiguration in code<p>The original answer is right (try it!).  You can use ServiceBehaviorAttribute.ConfigurationName to specify which service to look up in the config file, for example to select among S1 and S2 below...</p><font color="#0000ff" size=2> <p>&lt;</font><font color="#800000" size=2>services</font><font color="#0000ff" size=2>&gt;</p> <p>&lt;</font><font color="#800000" size=2>service</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>name</font><font color="#0000ff" size=2>=</font><font size=2>&quot;S1</font><font size=2>&quot;</font><font color="#0000ff" size=2>&gt; ...</font></p><font color="#0000ff" size=2> <p>&lt;<font color="#800000" size=2>service</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>name</font><font color="#0000ff" size=2>=</font><font color="#000000" size=2>&quot;S2</font><font color="#000000" size=2>&quot;</font><font color="#0000ff" size=2>&gt; ...</p></font></font>Tue, 17 Oct 2006 08:03:07 Z2006-11-15T20:30:31Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#683d6d8e-4ea5-4985-9c61-c8fc5eea4aaahttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#683d6d8e-4ea5-4985-9c61-c8fc5eea4aaaB Bukovicshttp://social.msdn.microsoft.com/Profile/en-US/?user=B%20BukovicsSpecifying behaviorConfiguration in codeI'm sorry if I'm not making my problem clear.  No, the original answer is not correct based on my original question.  Let me try to state this problem one more time.<br><br>I am creating all of my services (ServiceHost instances) in code.  I have NO entries at all in my app.config for services, and need to keep it that way.  I create my using reflection.  However, I do wish to have serviceBehaviors declared in my app.config such as this:<br><br>&lt;behaviors&gt;<br>    &lt;serviceBehaviors&gt;<br>        &lt;behavior name=&quot;defaultServiceBehavior&quot;&gt;<br>            &lt;serviceThrottling maxConcurrentCalls=&quot;32&quot;          maxConcurrentSessions=&quot;20&quot;/&gt;<br>        &lt;/behavior&gt;<br>    &lt;/serviceBehaviors&gt;<br>&lt;/behaviors&gt;<br><br>So the scenario is that I only define behaviors in the app.config, not individual services.  I never want to see any &lt;service&gt; attributes in my app.config.  <br><br>When I create my ServiceHost objects (in code), I need to find a way to specify a serviceBehavior configuration name (e.g. &quot;defaultServiceBehavior&quot;).  This is similar in concept to what I can do right now when creating bindings (also in code).  For example, WSHttpBinding has a constructor that accepts the name of a binding config entry.  If I construct a new WSHttpBinding(&quot;myBindingConfig&quot;), then it uses the binding config declared in my app.config like this:<br><br>        &lt;bindings&gt;<br>            &lt;wsHttpBinding&gt;<br>                &lt;binding name=&quot;myBindingConfig&quot; receiveTimeout=&quot;00:10:00&quot;&gt;<br>                    &lt;security mode=&quot;None&quot; /&gt;<br>                &lt;/binding&gt;<br>            &lt;/wsHttpBinding&gt;<br>        &lt;/bindings&gt;<br><br>I must be missing something because this can't possibly be this difficult.  There's got to be a way to specifiy serviceBehaviors in the app.config and actually reference them when creating the ServiceHost objects in code.<br><br>Thanks.<br><br>Bruce<br><br>Wed, 15 Nov 2006 20:40:47 Z2006-11-15T20:40:47Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#8cb8fd62-b66c-45da-9db7-568e1c7c1743http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#8cb8fd62-b66c-45da-9db7-568e1c7c1743Tolo Oliverhttp://social.msdn.microsoft.com/Profile/en-US/?user=Tolo%20OliverSpecifying behaviorConfiguration in code<p class=MsoNormal><span style="" lang=EN-GB>Hi,</span></p> <p class=MsoNormal><span style="" lang=EN-GB>I’m wondering if there is an easy way to read the behaviors from the app.config file and inject them into a ServiceHost object.</span></p> <p class=MsoNormal><span style="" lang=EN-GB>I can try to create a dummy service and copy de behaviors between the dummy one and the real ones but I would prefer a better solution if it’s possible. <br></span></p><p class=MsoNormal><span style="" lang=EN-GB>Thanks</span></p>Fri, 17 Nov 2006 14:10:18 Z2006-11-17T14:10:18Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#02127e5a-b177-411a-891b-6937de07418fhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#02127e5a-b177-411a-891b-6937de07418fDave Bettinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dave%20BettinSpecifying behaviorConfiguration in code<p>Tolo,</p> <p>I am not completely sure what you trying to accomplish but configured behaviors and their association to a ServiceHost are supported in WCF. </p> <p>This example below shows how a service binds to behaviors in configuration. The service references a named behavior configuration. The behaviors declared in the named configuration will properly be &quot;injected&quot; into the service host. Is that what you are trying to achieve?</p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;<br>&lt;configuration&gt;<br>  &lt;system.serviceModel&gt;<br>    &lt;services&gt;<br>      &lt;service <br>          name=&quot;Microsoft.ServiceModel.Samples.CalculatorService&quot;<br>          behaviorConfiguration=&quot;CalculatorServiceBehavior&quot;&gt;<br><br>        &lt;endpoint address=&quot;&quot;<br>                  binding=&quot;wsHttpBinding&quot;<br>                  contract=&quot;Microsoft.ServiceModel.Samples.ICalculatorConcurrency&quot; /&gt;<br>     <br>      &lt;/service&gt;<br>    &lt;/services&gt;</p> <p>    &lt;!--For debugging purposes set the includeExceptionDetailInFaults attribute to true--&gt;<br>    &lt;behaviors&gt;<br>      &lt;serviceBehaviors&gt;<br>        &lt;behavior name=&quot;CalculatorServiceBehavior&quot;&gt;<br>          &lt;serviceMetadata httpGetEnabled=&quot;True&quot;/&gt;<br>          &lt;serviceDebug includeExceptionDetailInFaults=&quot;False&quot; /&gt;<br>        &lt;/behavior&gt;<br>      &lt;/serviceBehaviors&gt;<br>    &lt;/behaviors&gt;</p> <p>  &lt;/system.serviceModel&gt;</p> <p>&lt;/configuration&gt;<br></p>Fri, 17 Nov 2006 16:01:21 Z2006-11-17T16:01:21Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#f7834569-43d8-4cf7-b7d3-19574564775fhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#f7834569-43d8-4cf7-b7d3-19574564775fTolo Oliverhttp://social.msdn.microsoft.com/Profile/en-US/?user=Tolo%20OliverSpecifying behaviorConfiguration in code<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Geneva, Arial, Sans-serif">Hi,</FONT></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Geneva, Arial, Sans-serif">&nbsp;</FONT></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Geneva, Arial, Sans-serif">I know that I can configure the behaviors and the services in the configuration file, but I don’t want to do that. I need to create the ServiceHost in my code, read the configuration file and then apply the defined behaviors. I’m looking for an easy way to do it ;-)</FONT></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Geneva, Arial, Sans-serif">&nbsp;</FONT></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Geneva, Arial, Sans-serif">Thanks</FONT></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Times New Roman"></FONT></SPAN>&nbsp;</P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB><FONT face="Times New Roman"></FONT></SPAN>&nbsp;</P>Fri, 17 Nov 2006 17:16:59 Z2006-11-17T17:16:59Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#3bda6734-d68d-4c2b-9ebb-ef02874b9c4dhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#3bda6734-d68d-4c2b-9ebb-ef02874b9c4dDave Bettinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dave%20BettinSpecifying behaviorConfiguration in code<p>Where are the behaviors defined? In the configuration file? </p> <p>What are you reading from the configuration file?</p>Fri, 17 Nov 2006 17:25:53 Z2006-11-17T17:25:53Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#08842b64-a957-435f-82e7-df6ca71435ffhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#08842b64-a957-435f-82e7-df6ca71435ffBrian McNamara - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Brian%20McNamara%20-%20MSFTSpecifying behaviorConfiguration in code<p>I have merged another thread with a similar question.</p> <p>Bruce, unfortunately I think it may be the case that we do not offer any convenient OM for what you want to do.  Note that we know of scenarios for using &lt;binding&gt;s without using a &lt;service&gt;, but I don't think we feel we know a reason for wanting to use &lt;behavior&gt;s without a &lt;service&gt;.  Can you describe your motivation for not putting the &lt;service&gt; stuff in your app.config?</p> <p>See the another post in this thread by Tolo for one possible workaround; you can configure a &quot;dummy&quot; &lt;service&gt;, new up a dummy ServiceHost, and invoke it's ApplyConfiguration in order to force the dummy to load behaviors, and then copy the behaviors over from the dummy.  </p>Sat, 18 Nov 2006 00:42:51 Z2006-11-18T00:42:58Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#5e91fa95-93fb-43be-98b5-483d2b6f93dfhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#5e91fa95-93fb-43be-98b5-483d2b6f93dfTolo Oliverhttp://social.msdn.microsoft.com/Profile/en-US/?user=Tolo%20OliverSpecifying behaviorConfiguration in code<P><SPAN lang=EN-GB style="FONT-SIZE: 9.5pt; COLOR: black">Hi,</SPAN></P> <P><SPAN lang=EN-GB style="FONT-SIZE: 9.5pt; COLOR: black">I have created a class to load the behaviors. I did not have time to fully test it, so be careful.</SPAN></P> <P><SPAN lang=EN-GB style="FONT-SIZE: 9.5pt">To use it you need to define a IBehaviorFactory for each Behavior class that you want to handle (see </SPAN><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">ServiceMetadataBehaviorFactory) and then register that class to associate it with its configuration element. For example<SPAN style="COLOR: teal">:</SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN style="COLOR: teal">BehaviorsLoader</SPAN>.RegisterBehaviorFactory(<SPAN style="COLOR: blue">typeof</SPAN>(<SPAN style="COLOR: teal">ServiceMetadataPublishingElement</SPAN>), <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: teal">ServiceMetadataBehaviorFactory</SPAN>());</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">And to use it:</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; COLOR: teal; FONT-FAMILY: 'Courier New'">BehaviorsLoader</SPAN><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">.LoadBehavior(svh, behaviorName);</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <HR id=[object]> </SPAN><FONT face="Courier New, Courier, Monospace"><FONT size=2><FONT color=#808080 size=2> <P></P></FONT><FONT size=2><FONT size=2><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><SPAN> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes">///</SPAN><SPAN lang=EN-GB style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"> </SPAN><SPAN lang=EN-GB style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes">&lt;summary&gt;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> Used to create the IServiceBehavior using the BehaviorExtensionElement information<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">interface</SPAN> <SPAN style="COLOR: teal">IBehaviorFactory<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">IServiceBehavior</SPAN> Create(<SPAN style="COLOR: teal">BehaviorExtensionElement</SPAN> element);<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> Helper class to load behaviors into a sevicehost object<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">BehaviorsLoader<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: teal">Dictionary</SPAN>&lt;<SPAN style="COLOR: teal">Type</SPAN>, <SPAN style="COLOR: teal">IBehaviorFactory</SPAN>&gt; equivalences = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">Dictionary</SPAN>&lt;<SPAN style="COLOR: teal">Type</SPAN>, <SPAN style="COLOR: teal">IBehaviorFactory</SPAN>&gt;();<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> Associate the BehaviorExtensionElement elements with the right factorie<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;param name="elementType"&gt;&lt;/param&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;param name="factory"&gt;&lt;/param&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN> RegisterBehaviorFactory(<SPAN style="COLOR: teal">Type</SPAN> elementType, <SPAN style="COLOR: teal">IBehaviorFactory</SPAN> factory)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>equivalences[elementType] = factory;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> Load the behavior in a ServiceHost object<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;param name="host"&gt;&lt;/param&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;param name="behaviorName"&gt;&lt;/param&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN> LoadBehavior(<SPAN style="COLOR: teal">ServiceHost</SPAN> host, <SPAN style="COLOR: blue">string</SPAN> behaviorName)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">ServiceBehaviorElement</SPAN> behaviorElement = GetServiceBehaviorElement(behaviorName);<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (behaviorElement != <SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">BehaviorExtensionElement</SPAN> element = behaviorElement[<SPAN style="COLOR: maroon">0</SPAN>];<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">IBehaviorFactory</SPAN> factory = ResolveElement(element.GetType());<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (factory != <SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">IServiceBehavior</SPAN> obj = factory.Create(element);<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (obj!=<SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// Type registered?, remove it before add the new behavior<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (host.Description.Behaviors.Contains(obj.GetType()))<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>host.Description.Behaviors.Remove(obj.GetType());<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>host.Description.Behaviors.Add(obj);<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> Locate the IBehaviorFactory associated to elementType<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;param name="elementType"&gt;&lt;/param&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;returns&gt;&lt;/returns&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: teal">IBehaviorFactory</SPAN> ResolveElement(<SPAN style="COLOR: teal">Type</SPAN> elementType)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">IBehaviorFactory</SPAN> factory;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(equivalences.TryGetValue(elementType, <SPAN style="COLOR: blue">out</SPAN> factory))<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> factory;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: teal">ServiceBehaviorElement</SPAN> GetServiceBehaviorElement(<SPAN style="COLOR: blue">string</SPAN> behaviorName)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">ServiceBehaviorElement</SPAN> element = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (!<SPAN style="COLOR: blue">string</SPAN>.IsNullOrEmpty(behaviorName))<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">BehaviorsSection</SPAN> secBehavior = (<SPAN style="COLOR: teal">BehaviorsSection</SPAN>)<SPAN style="COLOR: teal">ConfigurationManager</SPAN>.GetSection(<SPAN style="COLOR: maroon">"system.serviceModel/behaviors"</SPAN>);<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (secBehavior.ServiceBehaviors.ContainsKey(behaviorName))<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>element = secBehavior.ServiceBehaviors[behaviorName];<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> element;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> ServiceMetadataBehaviorFactory<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">ServiceMetadataBehaviorFactory</SPAN>: <SPAN style="COLOR: teal">IBehaviorFactory<o:p></o:p></SPAN></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>#region</SPAN><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"> IBehaviorFactory Members<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: teal">IServiceBehavior</SPAN> Create(<SPAN style="COLOR: teal">BehaviorExtensionElement</SPAN> element)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">ServiceMetadataPublishingElement</SPAN> metElement = element <SPAN style="COLOR: blue">as</SPAN> <SPAN style="COLOR: teal">ServiceMetadataPublishingElement</SPAN>;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(metElement==<SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">ServiceMetadataBehavior</SPAN> behavior = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">ServiceMetadataBehavior</SPAN>();<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>behavior.HttpGetEnabled = metElement.HttpGetEnabled;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>behavior.HttpGetUrl = metElement.HttpGetUrl;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: blue">return</SPAN> behavior;<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>#endregion<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">&nbsp;&nbsp;&nbsp; </SPAN></SPAN></P></FONT></FONT></FONT></FONT>Sat, 18 Nov 2006 02:02:38 Z2006-11-18T02:02:38Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#5d5e4640-cfa9-4be4-baa6-316a9a7027b1http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#5d5e4640-cfa9-4be4-baa6-316a9a7027b1B Bukovicshttp://social.msdn.microsoft.com/Profile/en-US/?user=B%20BukovicsSpecifying behaviorConfiguration in codeIt seems that Tolo and I are asking for exactly the same thing.  We need a way to create ServiceHost instances in code but load the associated behaviors from entries in the App.config.<br><br>My reason for this need is due to the way we are declaring our services.  We use custom attributes on our service interfaces to provide additional meta data about each service.  We then use reflection at runtime to identify all services within each assembly and create ServiceHost instances based on the additional meta data that we've provided.  On the client side I create proxies instead of ServiceHost objects.  The service host as well as the client application only need to know the list of assemblies to load at runtime. <br><br>The one disadvantage to our approach is that we  are now declaring much of the service configuration as compiled meta data with each service instead of placing it in an app.config.  This does require a change to the source if you want to change an attribute of the service.  However, this does  improve the development experience.  It makes the development of each service much easier since you simply need to add one additional attribute to the service.  You don't have to add anything to the client or service host app.config.  If you are developing a lot of independent services, that is important.  And, it prevents someone from modifying the most important service attributes externally.  For us, it is important that our applications work the same way every time, no matter where they are deployed.  Defining the services internally as compiled metadata ensures that we always know exactly what bindings, endpoints and other important attributes are in use.  <br><br>So that's the reason why I'm doing this.  I'll take a look at Tolo's code and see if I can make use of it in my framework.  <br><br>Thanks for your help.<br><br>Bruce Bukovics<br>.NET 2.0 Interoperability Recipes http://www.apress.com/book/bookDisplay.html?bID=10116<br>Pro WF:  Windows Workflow in .NET 3.0 http://www.apress.com/book/bookDisplay.html?bID=10213<br>Mon, 20 Nov 2006 14:42:01 Z2006-11-20T14:42:01Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#7f52dc3d-f5b2-4751-87d3-b05815f9913dhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d00d2a87-4d89-4510-9569-fab73a3ad070#7f52dc3d-f5b2-4751-87d3-b05815f9913dEric Garzahttp://social.msdn.microsoft.com/Profile/en-US/?user=Eric%20GarzaSpecifying behaviorConfiguration in codeI am trying to do the same thing and my friend came up with this code for me and it works great!  <br><br>To use it put the WCFAppConfigUtility class somewhere in your Utility section and then to use it just call Add Behavior.  Works like a charm.<br><br><font color="#0000ff" size=2><font color="#0000ff" size=2> <p>private</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2> AddBehavior(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>string</font></font><font size=2> behaviorConfiguration)<br>{<br></font><font color="#2b91af" size=2><font color="#2b91af" size=2>    Dictionary</font></font><font size=2>&lt;</font><font color="#2b91af" size=2><font color="#2b91af" size=2>Type</font></font><font size=2>, </font><font color="#0000ff" size=2><font color="#0000ff" size=2>object</font></font><font size=2>&gt; behaviors =<br></font><font color="#2b91af" size=2><font color="#2b91af" size=2>        WCFAppConfigUtility</font></font><font size=2>.GetServiceBehavior(behaviorConfiguration);<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>    foreach</font></font><font size=2> (</font><font color="#2b91af" size=2><font color="#2b91af" size=2>Type</font></font><font size=2> bType </font><font color="#0000ff" size=2><font color="#0000ff" size=2>in</font></font><font size=2> behaviors.Keys)<br>    {<br>        _host.Description.Behaviors.Remove(bType);<br>        _host.Description.Behaviors.Add((</font><font color="#2b91af" size=2><font color="#2b91af" size=2>IServiceBehavior</font></font><font size=2>)behaviors[bType]);<br>    }<br>}</p></font><font size=2><br> <p></font><font color="#0000ff" size=2><font color="#0000ff" size=2><br><br><br>public</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>static</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>partial</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>class</font></font> <font color="#2b91af" size=2><font color="#2b91af" size=2>WCFAppConfigUtility<br></font></font><font size=2>{<br></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;summary&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2><font color="#008000" size=2> Gets a listing of the service behaviors that correspond to the </font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;paramref name=&quot;name&quot;/&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2><font color="#008000" size=2> inside of App.Config.<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;/summary&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;param name=&quot;name&quot;&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2>The name.</font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;/param&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;returns&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2>A list of all behaviors tied to </font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;paramref name=&quot;name&quot;/&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2> inside of App.Config.</font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;/returns&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;exception cref=&quot;ApplicationException&quot;&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2>Occurs when the </font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;paramref name=&quot;name&quot;/&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2> is not located in the App.Config.</font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;/exception&gt;<br></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>    public</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>static</font></font> <font color="#2b91af" size=2><font color="#2b91af" size=2>Dictionary</font></font><font size=2>&lt;</font><font color="#2b91af" size=2><font color="#2b91af" size=2>Type</font></font><font size=2>, </font><font color="#0000ff" size=2><font color="#0000ff" size=2>object</font></font><font size=2>&gt; GetServiceBehavior(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>string</font></font><font size=2> name)<br>    {<br></font><font color="#2b91af" size=2><font color="#2b91af" size=2>        Dictionary</font></font><font size=2>&lt;</font><font color="#2b91af" size=2><font color="#2b91af" size=2>Type</font></font><font size=2>, </font><font color="#0000ff" size=2><font color="#0000ff" size=2>object</font></font><font size=2>&gt; behaviorList = </font><font color="#0000ff" size=2><font color="#0000ff" size=2>new</font></font> <font color="#2b91af" size=2><font color="#2b91af" size=2>Dictionary</font></font><font size=2>&lt;</font><font color="#2b91af" size=2><font color="#2b91af" size=2>Type</font></font><font size=2>, </font><font color="#0000ff" size=2><font color="#0000ff" size=2>object</font></font><font size=2>&gt;();<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>        using</font></font><font size=2> (</font><font color="#2b91af" size=2><font color="#2b91af" size=2>DisposableSemaphore</font></font><font size=2> sem = </font><font color="#2b91af" size=2><font color="#2b91af" size=2>DisposableSemaphore</font></font><font size=2>.CreateSingle(UniqueName))<br>        {<br></font><font color="#2b91af" size=2><font color="#2b91af" size=2>            Configuration</font></font><font size=2> config = GetConfiguration();<br></font><font color="#2b91af" size=2><font color="#2b91af" size=2>            BehaviorsSection</font></font><font size=2> behaviorData = (</font><font color="#2b91af" size=2><font color="#2b91af" size=2>BehaviorsSection</font></font><font size=2>)config.GetSection(</font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;system.serviceModel/behaviors&quot;</font></font><font size=2>);<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>            if</font></font><font size=2> (!behaviorData.ServiceBehaviors.ContainsKey(name))<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>                throw</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>new</font></font> <font color="#2b91af" size=2><font color="#2b91af" size=2>ApplicationException</font></font><font size=2>(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>string</font></font><font size=2>.Format(</font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;Service Behavior {0} was not found.&quot;</font></font><font size=2>, name));<br></font><font color="#2b91af" size=2><font color="#2b91af" size=2>            ServiceBehaviorElement</font></font><font size=2> serviceElement = behaviorData.ServiceBehaviors[name];<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>            foreach</font></font><font size=2> (</font><font color="#2b91af" size=2><font color="#2b91af" size=2>BehaviorExtensionElement</font></font><font size=2> behaviorPart </font><font color="#0000ff" size=2><font color="#0000ff" size=2>in</font></font><font size=2> serviceElement)<br>            {<br>                behaviorList.Add(behaviorPart.BehaviorType, behaviorPart.CreateBehavior());<br>            }<br>        }<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>        return</font></font><font size=2> behaviorList;<br>    }<br>}<br><br><font color="#0000ff" size=2><font color="#0000ff" size=2></p> <p>public</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>static</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>class</font></font> <font color="#2b91af" size=2><font color="#2b91af" size=2>System_ServiceModel_Configuration_BehaviorExtensionElement_Extension<br></font></font><font size=2>{<br></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;summary&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2><font color="#008000" size=2> Creates a behavior extension based on the current configuration settings. This is<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2><font color="#008000" size=2> accomplished by exposing the internal protected method BehaviorExtensionElement.CreateBehavior<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2><font color="#008000" size=2> through Reflection.<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;/summary&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;param name=&quot;element&quot;&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2>The element.</font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;/param&gt;<br></font></font><font color="#808080" size=2><font color="#808080" size=2>    ///</font></font><font color="#008000" size=2> </font><font color="#808080" size=2><font color="#808080" size=2>&lt;returns&gt;</font></font><font color="#008000" size=2><font color="#008000" size=2>The behavior extension.</font></font><font color="#808080" size=2><font color="#808080" size=2>&lt;/returns&gt;<br></font></font><font color="#0000ff" size=2><font color="#0000ff" size=2>    public</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>static</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>object</font></font><font size=2> CreateBehavior(</font><font color="#0000ff" size=2><font color="#0000ff" size=2>this</font></font> <font color="#2b91af" size=2><font color="#2b91af" size=2>BehaviorExtensionElement</font></font><font size=2> element)<br>    {<br></font><font color="#0000ff" size=2><font color="#0000ff" size=2>        return</font></font><font size=2> element.GetType().GetMethod(</font><font color="#a31515" size=2><font color="#a31515" size=2>&quot;CreateBehavior&quot;</font></font><font size=2>,<br>            System.Reflection.</font><font color="#2b91af" size=2><font color="#2b91af" size=2>BindingFlags</font></font><font size=2>.Instance |<br>            System.Reflection.</font><font color="#2b91af" size=2><font color="#2b91af" size=2>BindingFlags</font></font><font size=2>.NonPublic).Invoke(<br>                element, </font><font color="#0000ff" size=2><font color="#0000ff" size=2>new</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>object</font></font><font size=2>[0] { });<br>    }<br>}</p></font></font>Fri, 17 Oct 2008 13:46:01 Z2008-10-17T13:46:01Z