C# 可观察到反应式扩展。使用和WCF异步调用
我无法理解如何使用Observer。使用 我有以下代码C# 可观察到反应式扩展。使用和WCF异步调用,c#,system.reactive,C#,System.reactive,我无法理解如何使用Observer。使用 我有以下代码 public void Test() { Observable.Using( () => new GFSClientServiceClient(), (c) => ObservableGetParameters(c)) .Subscribe( (response) => D
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);
}
公共无效测试()
{
可观察的。使用(
()=>新的GFSClientServiceClient(),
(c) =>可观测参数(c))
.订阅(
(响应)=>Debug.Print(“响应”),
(ex)=>Debug.Print(“{0}错误:{1}”,名称,ex.Message),
()=>Debug.Print(“{0}完成”,名称)
);
}
专用静态函数ObserviceGetParameters(GFSClientService.GFSClientServiceClient客户端)
{
返回Observable.FromAsyncPattern(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() {}
}
公共无效测试()
{
可观察。使用(()=>new Client(),
(c) =>可观测参数(c))
.Subscribe((响应)=>Debug.Print(“响应”),
(ex)=>Debug.Print(“{0}错误:{1}”,“名称”,ex.Message),
()=>Debug.Print(“{0}complete”,“name”);
}
专用静态IObservable ObservableGetParameters(客户端)
{
返回Observable.FromAsyncPattern(client.BeginGetParameters,client.EndGetParameters)();
}
公共类客户端:IDisposable{
公共IAsyncResult BeginGetParameters(异步回调cb,对象o){
返回默认值(IAsyncResult);
}
公共字典EndGetParameters(IAsyncResult res){
返回默认值(字典);
}
public void Dispose(){}
}