2011-12-20 50 views
0

我會盡力解釋我想要的代碼,原因不能用文字來表達。如何實現封裝其他WCF服務的WCF服務的概念?

我有一些類型的資源,我封裝及其使用的WCF服務,我有控制訪問該資源的資源管理器,它也是一個WCF服務,像這樣:

//Allows only one client to use it at the same time... 
public interface IResource 
{ 
    string GetResourceDescription(); 
    void DoWork(); 
    void BeginWork(); 
    void EndWork(); 
} 

//Governs access and location of resources 
public interface IResourceManager 
{ 
    IEnumerable<string> GetResourcesDescriptions(); 
    bool IsResourceAvailable(string resourceDescription); 
    void BeginWorkWith(string resourceDescription); 
    void DoWorkWith(string resourceDescription) 
    void EndWorkWith(string resourceDescription); 
} 

我不要在此代碼一樣的是,與IResourceManager工作時,我需要總是告訴我要使用業務操作有什麼資源,所以基本上IResourceManager具有相同的服務操作爲IResource但需要額外的IResource標識符作爲參數。

我要的是:

public interface IResourceManager 
{ 
    IEnumerable<string> GetResourcesDescriptions(); 
    //I want it to return service proxy (ICommunicationObject) 
    IResource GetResource(string resourceDescription); 
} 

首先這是不可能的,第二,客戶端不能與IResource直接在網絡層進行通信(沒有直接連接)。

到目前爲止,我只找到一個沒有醜陋的解決方案,創建一個客戶端的包裝,模仿這種行爲。如何實現和使用這樣的WCF服務?

回答

0

請的對象從服務操作返回的僅是數據的頭腦。在通信渠道的另一端,這些對象將是「死」(將只包含數據,沒有方法)。處理它的唯一方法就是你解決問題的方式。客戶端包裝聽起來不錯,我認爲這是合理的解決方案。