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
Post a Comment