簡體   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