2009-06-30 7 views
12

特定のサービスインスタンスと操作のコンテキスト内で実行している場合、現在実行中のサービスインスタンスにどのようにアクセスできますか?サービスインスタンスがある私は見つけることができ、既存のコンテキストに任意の特定の共通の基底クラスやインターフェイスのみの経路から継承しません:現在のコンテキストでWCFサービスインスタンスにアクセスするにはどうすればよいですか?

OperationContext.Current 

が、私は実際のサービスを参照するすべてのプロパティを見つけることができないようインスタンスそのものなので、それを私が知っているべきものにキャストし、その上で操作を実行することができます。

私がこれをやっている理由を探ることなく(それは無関係です)、私が探している参照を見つける方法があれば教えてください。

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. 
    } 
} 
+0

申し訳ありませんが、このIIRCのプロパティを持っている必要があり、あなたはもっと正確にあなたが探しているものを少し説明できますか? OperationContext.Currentは、必要なものすべてをある方法で提供する必要があります。 –

+0

私は例を使って質問を更新しました。 –

+0

"Whatever"クラスのソースコードを制御していないのに、インスタンスデータを渡す必要があるようです。私は正しい? –

答えて

18
var myService = OperationContext.Current.InstanceContext.GetServiceInstance(); 
0

OperationContext.Current

関連する問題