I'm trying in a single method to return the result of a HttpWebRequest POST method via the Reactive interface IObservable. I've managed to do this for a GET method using the code below:
var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(url);
request.Method = method;
request.Accept = GetHttpType();
request.CookieContainer = new CookieContainer();
return Observable.FromAsyncPattern(request.BeginGetResponse, ar => ProcessResponse(method, ar, request))()
.Select(r => r);
But I am unsure how to chain together the async observer of writing to the request stream with the reading of the response stream which is required for a HTTP POST operation. How to do connect the following variables obs1
& obs2
together so that I can return obs2?
var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(url);
var type = GetHttpType();
request.Method = method;
request.Accept = type;
request.ContentType = type;
request.CookieContainer = new CookieContainer();
var data = Serialize(requestResource);
var obs1 = Observable.FromAsyncPattern(request.BeginGetRequestStream, ar1 => ProcessRequest(method, data, ar1, request))
var obs2 = Observable.FromAsyncPattern(request.BeginGetResponse, ar2 => ProcessResponse(method, ar2, request))();
// How do I connect obs1 And obs2 together...
return obs2;
I would have thought the following should work but the 'ProcessResponse' method is never called, does anyone know why?
var obs1 = Observable.FromAsyncPattern(request.BeginGetRequestStream, ar1 => ProcessRequest(method, data, ar1, request))();
var obs2 = Observable.FromAsyncPattern(request.BeginGetResponse, ar2 => ProcessResponse(method, ar2, request));
return obs1.SelectMany(a => obs2(), (a, b) => b);