c# - Simple example of IServiceBehavior and ApplyDispatchBehavior -


i trying plug unity wcf service library service behavior.

i need simple bare bones example of service behavior.

all want setup ioc unity container on startup of wcf service.

note: not using wcf service application. don't have access of asp.net ways of doing this. concept point of view, service behavior seems elegant method. don't know how set 1 (what code need, update config files, etc).

if want control instancing of wcf service instances, you'll need service behavior plug iinstanceprovider that. can find simple provider implementation (for ioc container) in post interface @ http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/31/wcf-extensibility-iinstanceprovider.aspx.

per comments, if need simple iservicebehavior, here's sample implementation can use.

public class stackoverflow_6539963 {     public class myservicebehaviorattribute : attribute, iservicebehavior     {         public void addbindingparameters(servicedescription servicedescription, servicehostbase servicehostbase, collection<serviceendpoint> endpoints, bindingparametercollection bindingparameters)         {         }          public void applydispatchbehavior(servicedescription servicedescription, servicehostbase servicehostbase)         {             console.writeline("in myservicebehaviorattribute.applydispatchbehavior");             // whatever initialization need         }          public void validate(servicedescription servicedescription, servicehostbase servicehostbase)         {         }     }     [servicecontract]     public interface itest     {         [operationcontract]         string echo(string text);     }     [myservicebehavior]     public class service : itest     {         public string echo(string text)         {             return text;         }     }     public static void test()     {         string baseaddress = "http://" + environment.machinename + ":8000/service";         servicehost host = new servicehost(typeof(service), new uri(baseaddress));         host.addserviceendpoint(typeof(itest), new basichttpbinding(), "");         host.open();         console.writeline("host opened");          console.write("press enter close host");         console.readline();         host.close();     } } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -