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

1

6

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.

Arvizu answered 8/11, 2012 at 17:42 Comment(0)
C
11

Try the OperationContext - it has a .Host property:

var host = OperationContext.Current.Host;

See the MSDN documentation for more details.

Clydeclydebank answered 8/11, 2012 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.