反应式扩展Observable.Using和WCF异步调用
本文关键字:WCF 异步 调用 Using 扩展 Observable 反应式 | 更新日期: 2023-09-27 18:27:42
我很难理解如何使用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);
}
我似乎无法使using子句起作用。它一直告诉我,类型是无法推断的,但我不明白为什么?有人知道吗?
编辑:
我的第一个答案不正确。很抱歉。你可能想做这样的事情:
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() {}
}