Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF: How to get the reference of created instance from ServiceHost (WCF 4.5)

In my server side console program, multiple ServiceHost objects are created and working in PerSession mode, not singleton. Therefore, a new server side object will be created when a new session started.

The problem is: How can I know which is the right ServiceHost object linked with the new created server side object? I do need this link information for further operations.

Can I get the ServiceHost information from the new created server side object? By converting it into another interface or class? Or, can I hook the instance creating process of ServiceHost?

Any idea?

Thanks a lot.

like image 254
scegg Avatar asked Nov 08 '12 17:11

scegg


1 Answers

Try the OperationContext - it has a .Host property:

var host = OperationContext.Current.Host;

See the MSDN documentation for more details.

like image 175
marc_s Avatar answered Nov 06 '22 15:11

marc_s