12
如果我在特定服务实例和操作的上下文中执行,如何访问当前正在执行的服务实例?服务实例不从任何特定的公共基类或接口,唯一的途径在现有的情况下,我能找到继承是:如何在当前上下文中访问WCF服务实例?
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.
}
}
对不起的属性,你能解释多一点正是你在找什么? OperationContext.Current应该以这种或那种方式提供您需要的一切。 – 2009-06-30 08:47:46