繁体   English   中英

如何在当前上下文中访问WCF服务实例?

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

如果我在特定服务实例和操作的上下文中执行,如何访问当前正在执行的服务实例? 服务实例不从任何特定的公共基类或接口继承,并且我可以找到进入现有上下文的唯一途径:

OperationContext.Current

但我似乎无法找到任何引用实际服务实例本身的属性,以便我可以将其转换为我应该知道的内容并对其执行操作。

没有探究我为什么这样做(这是无关紧要的),请告诉我是否有任何方法可以找到我想要的参考。

编辑:

[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的属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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