简体   繁体   中英

How do I get access to the WCF service instance in the current context?

If I am executing within the context of a particular service instance and operation, how do I get access to the currently-executing service instance? Service instances don't inherit from any specific common base class or interface and the only pathway into the existing context that I can find is:

OperationContext.Current

but I can't seem to find any properties that reference the actual service instance itself so that I can cast it to what I know it should be and perform operations on it.

Without exploring why I am doing this (it's irrelevant), please let me know if there is any way to find the reference I am looking for.

EDIT:

[ServiceContract]
public interface IInventory
{
    [OperationContract]
    List<DealInfo> ListDeals(DealQueryOptions options);
}

// This is the object I will need access to the current instance of
public class Inventory : ServiceBase<Inventory>, IInventory
{
    public List<DealInfo> ListDeals(DealQueryOptions options)
    {
        var obj = new Whatever(); // see below
    }
}

public class Whatever
{
    public Whatever()
    {
        // how do I get access to the service instance here?
        // assume that in this context we are not allowed to
        // pass the service instance to this class; this class
        // must automatically discover the instance itself.
    }
}
var myService = OperationContext.Current.InstanceContext.GetServiceInstance();

OperationContext.Current应具有此IIRC的属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM