Реактивные расширения Observable.Using и асинхронный вызов WCF - PullRequest
1 голос
/ 13 марта 2012

У меня проблемы с пониманием того, как использовать Observer. Использование

У меня есть следующий код

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

Я не могу заставить работать предложение. Он постоянно говорит мне, что типы не могут быть выведены, но я не понимаю, почему? У кого-нибудь есть идеи?

1 Ответ

2 голосов
/ 14 марта 2012

EDIT:

Мой первый ответ был неверным. Извини за это. Вы, вероятно, хотите сделать что-то вроде этого:

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() {}
}
...