Programmatically set InstanceContextMode

前端 未结 3 1015
死守一世寂寞
死守一世寂寞 2021-02-06 21:52

Is there a way to do this ...

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

...pro

3条回答
  •  时光取名叫无心
    2021-02-06 22:11

    Even though the original answer contains the solution it is Just a straight answer to the question

    ServiceHost host = new ServiceHost(typeof(YourService)); //Or get the Servicehost
    ((ServiceBehaviorAttribute)host.Description.
    Behaviors[typeof(ServiceBehaviorAttribute)]).InstanceContextMode 
    = InstanceContextMode.Single;
    

提交回复
热议问题