2012-03-13 7 views
1

Je vais avoir du mal à comprendre comment utiliser Observer.Usingextensions réactives Observable.Using et WCF async appel

J'ai le code suivant

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); 
    } 

Je ne peux pas sembler obtenir la utilisant la clause pour travailler. Il ne cesse de me dire que les types ne peuvent pas être déduits, mais je ne vois pas pourquoi? Quelqu'un a une idée?

Répondre

2

EDIT:

Ma première réponse était incorrecte. Désolé pour ça. Vous voulez probablement faire quelque chose comme ceci:

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

Merci Richard. Je vois bien que le code ce que j'étais dong tort ... –

Questions connexes