Accessing ServiceHost in WCF from another Servicehost C#
I have 2 contracts hosted in two servicehosts i need to have a singleton object in the first contract so when the other servicehost try to create an object from that class it just retrieve the same object from the first servicehost,
which might mean i need to find away to access the servicehost and get the object from it instead of creating开发者_开发技巧 a new one.. any idea?
thanks in advance
so, i think you can make the instance of the service class yourself, then pass this instance to both service hosts. I haven't tested this in depth though.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Calc: ICalc
{
}
var calc = new Calc();
var h1 = new ServiceHost(calc, baseAddress1);
var h2 = new ServiceHost(calc, baseAddress2);
精彩评论