.net - How to set ServiceThrottlingBehavior for IIS hosted WCF service programmatically -
i'm trying figure out shove object:
servicethrottlingbehavior stb = new servicethrottlingbehavior { maxconcurrentsessions = 100, maxconcurrentcalls = 100, maxconcurrentinstances = 100 };
i've found info on how configure in web.config i'm little confused that. used have stuff in our web.config looked this:
<service name="authenticationservice.authenticationservice" behaviorconfiguration="development"> <endpoint address="http://services.local/0.0.0.5/authenticationservice.svc" binding="basichttpbinding" bindingconfiguration="tupsoapbinding" contract="authenticationservice.servicedomain.isecurityservice" name="soapcatalogservice" /> </service>
if still used know how configure throttling via web.config, found take endpoints out of web.config , still worked , less maintenance since didn't have go update address different versions , environments anymore.
i've found info on how set programmatically on servicehost, i'm not creating servicehost programmatically. i'm letting iis take care of that.
so there programmatic way me set throttling without web.config , without having create servicehost myself?
edit: or there way me in web.config without having create <service />
entry every 1 of our services?
one way use markup in .svc file instruct iis use custom service host , custom service host factory. of course need have custom service host. example:
using system; using system.servicemodel; using system.servicemodel.description; public class myservicehost : servicehost { public myservicehost() : base() { } public myservicehost(type servicetype, params uri[] baseaddresses) : base(servicetype, baseaddresses) { } public myservicehost(object singletoninstance, params uri[] baseaddresses) : base(singletoninstance, baseaddresses) { } protected override void onclosing() { base.onclosing(); } protected override void applyconfiguration() { base.applyconfiguration(); this.description.behaviors.add(new servicethrottlingbehavior { maxconcurrentsessions = 100, maxconcurrentcalls = 100, maxconcurrentinstances = 100 }); } }
the key point above override of applyconfiguration()
, can add servicethrottlingbehavior
custom service host.
iis use servicehostfactory
instantiate myservicehost
, create custom service host factory, so:
public class myservicehostfactory : servicehostfactory { protected override servicehost createservicehost(type servicetype, params uri[] baseaddresses) { return new myservicehost(servicetype, baseaddresses); } }
the above code create actual instance of custom service host.
the final step alter markup of .svc file use custom service host , factory:
<%@ servicehost langauge="c#" service="mycompany.myservice" codebehind="myservice.svc.cs" factory="mycompany.myservicehostfactory" %>
the service name needs qualified name of service, , factory need qualified name of custom service host factory.
obviously, can add lot of stuff custom service host (we have monitoring , error handling in ours). done in .net 3.5, there may newer or additional ways in 4.0/4.5 (for example, know can specify factory in config file file-less activation, go in <system.servicemodel>
section, seem want avoid.)
Comments
Post a Comment