2012-03-13 116 views
1

我無法理解如何使用Observer.Using無擴展Observable.Using和WCF異步調用

我有下面的代碼

public void Test() 
    { 
     Observable.Using(
      () => new GFSClientServiceClient(), 
      (c) => ObservableGetParameters(c)) 
       .Subscribe(
        (response) => Debug.Print("response"), 
        (ex) => Debug.Print("{0} error: {1}", Name, ex.Message), 
        () => Debug.Print("{0} complete", Name) 
       ); 
    } 

    private static Func<IObservable<Dictionary<string, Dictionary<string, string>>>> ObservableGetParameters(GFSClientService.GFSClientServiceClient client) 
    { 
     return Observable.FromAsyncPattern<Dictionary<string, Dictionary<string, string>>>(client.BeginGetParameters, client.EndGetParameters); 
    } 

我似乎無法得到使用條款來工作。它一直告訴我,類型不能推斷,但我不明白爲什麼?任何人有任何想法?

回答

2

編輯:

我的第一個回答是不正確的。對於那個很抱歉。你可能想這樣做:

public void Test() 
{ 
    Observable.Using(() => new Client(), 
     (c) => ObservableGetParameters(c)) 
        .Subscribe((response) => Debug.Print("response"), 
        (ex) => Debug.Print("{0} error: {1}", "name", ex.Message), 
        () => Debug.Print("{0} complete", "name")); 
} 
private static IObservable<Dictionary<string, Dictionary<string, string>>> ObservableGetParameters(Client client) 
{ 
    return Observable.FromAsyncPattern<Dictionary<string, Dictionary<string, string>>>(client.BeginGetParameters, client.EndGetParameters)(); 
    } 
public class Client : IDisposable { 
public IAsyncResult BeginGetParameters(AsyncCallback cb, object o) { 
    return default(IAsyncResult); 
} 
public Dictionary<string, Dictionary<string, string>> EndGetParameters(IAsyncResult res) { 
    return default(Dictionary<string, Dictionary<string, string>>); 
} 
public void Dispose() {} 
} 
+0

謝謝理查德。我看到雖然代碼我是東錯了... – 2012-03-14 09:48:33