I have a simple Web API which returns an Iobservable. I am using HttpClient to get the Observable so that I can subscribe to it. My problem is the returned Iobservable on subscription sends out an 'empty' result.
SERVER
public IObservable<DataItem> GetDataItems()
{
return Observable.Generate(0, i => i < 10, i => i + 1,
i => new DataItem
{
Id = i,
Name = String.Format("Storage{0}",i)
});
}
CLIENT
public IObservable<DataItem> GetDataItems()
{
using (HttpClient apiClient = new HttpClient())
{
apiClient.BaseAddress = new Uri("http://localhost:9001");
apiClient.DefaultRequestHeaders.Add("x-user-authentication", "xxxxxx");
return apiClient
.GetAsync("api/xxxx/yyyy").Result.Content
.ReadAsAsync<DataItem>().ToObservable();
}
}
var source = GetDataItems();
List<DataItem> items = new List<DataItem>();
IDisposable consoleSubscription = source.Subscribe(
x => Console.WriteLine("{0}:{1}", x.Id, x.Name),
ex => Console.WriteLine("OnError : {0} ", ex.Message),
() => Console.WriteLine("Encountered End of Stream")
);
consoleSubscription.Dispose();
My issue is I am not getting any data back from the server. I get an 'Empty' observable. I wrote a unit test against my controller and it does give back the dataitems.
Any suggestions please help. Unable to understand where I am going wrong. There are no errors on server or client.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…