WCF Client proxy creation strategy with custom endpoint behavior -


i'd centralize creation of wcf proxies in wpf client application. during creation of each proxy i'd define programaticaly specific endpoint behaviors (adding localization headers etc) , define client credential settings (i'm using message level security username client credentials). creation of proxy should this:

public class servicechannelfactory {  public t createchannel<t, tservice>() t : clientbase<tservice>  {   var proxy = new t(bindingbuilder.getbinding(), endpointbuilder.getendpointaddress()); //!!!   proxy.endpoint.behaviors.add(new localizationendpointbehavior());   proxy.clientcredentials.username.username = applicationcontext;   proxy.clientcredentials.username.password = txtpassword.password;   return proxy;  } } 

and usage should this:

var scp = new servicechannelfactory(); var proxy = scp.createchannel<myserviceclient, icustomerservice>(); proxy.open(); try {     proxy.callservice(); } {     proxy.close(); } 

but i'm not able figure out how create the proxy object without using reflection (the //!!! commented line).

myserviceclient class generated vs>add service reference.

is there best-practices solution problem?

if add new() constraint, can create instance of generic type, assuming has paramaterless constructor.

public class servicechannelfactory  {      public t createchannel<t, tservice>()      tservice : class     t : clientbase<tservice>, new()     {          var proxy = new t();          //configure proxy here          return proxy;      }  } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -