asp.net web api - Calling WebApi from Windows Service -
i trying call following method onstart() method of windows service, windows service starts , stops , throws error.
static async task runasync() { lightspeedcontext<righthireunitofwork> _context; var client = new httpclient(); _context = new lightspeedcontext<righthireunitofwork>("default"); client.baseaddress = new uri("https://api.xyz.com/"); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.tryaddwithoutvalidation( "x-smarttoken", "1dfaaad541c45031c8b92bfab3ssssssssssb5644c368f3"); var content = new stringcontent("", encoding.utf8, "application/json"); string config = "v1/assessments?status=new"; httpresponsemessage response = null; try { response = await client.getasync(config); } catch (httprequestexception httpex) { // determine error here inspecting httpex.message } if (response.issuccessstatuscode) { listresult lr = await response.content.readasasync<listresult>(); list<smartrecruiters.assessmentorder> lasmtorders = lr.content; // other processing here
} } the onstart method follows:
protected override void onstart(string[] args) { this.writetofile("simple service started {0}"); // need call runasync method here... } i tried making onstart async, didn't help. thoughts on how can make call?
Comments
Post a Comment