.net - Is it possible to return the result of a HttpWebRequest POST method via IObservable interface -
i'm trying in single method return result of httpwebrequest post method via reactive interface iobservable. i've managed method using 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 unsure how chain async observer of writing request stream reading of response stream required http post operation. how connect following variables obs1
& obs2
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 connect obs1 , obs2 together... return obs2;
i have thought following should work 'processresponse' method never called, 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);
fromasyncpattern
expecting both beginaction , endaction methods arguments. think looking this:
httpwebrequest httprequest = (httpwebrequest)httpwebrequest.create("http://www.stackoverflow.com"); httprequest.method = "post"; var requestasync = observable.fromasyncpattern<stream>( httprequest.begingetrequeststream, httprequest.endgetrequeststream); var responseasync = observable.fromasyncpattern<webresponse>( httprequest.begingetresponse, httprequest.endgetresponse); requestasync() .selectmany(requeststream => { // requeststream.write return responseasync(); }) .subscribe(webresponse => { // complete });
let me know if writing request stream asynchronous , can update sample accordingly.
Comments
Post a Comment