i'm new azure webjobs, i'm trying use them make api call bing maps api when need it. triggered request on website, @ moment i'm trying figure out webjobs. created console app , manually added webjob sample website. of test webjobs (simple hello world type things) have worked fine, when try call bing maps api, webjob says completed part of code executed. here code webjob:
class program { static void main(string[] args) { program p = new program(); p.makeasync(); } public async void makeasync() { console.writeline("i'm call"); callme c = new callme(); bool x = await c.callbingmapsasync(49931); console.writeline("i called , result {0}", x); } } public class callme { public async task<bool> callbingmapsasync(int zip) { rootob lookups = await bingmaps.getlocations(zip); resource here = lookups.resourcesets[0].resources[0]; string city = here.address.locality; double lat = here.point.coordinates[0]; double lon = here.point.coordinates[1]; console.writeline("i looked {0} , found @ ({1} n, {2} w).",city, lat, lon); return true; } }
bingmaps.getlocations()
retrieves data , converts object format. when run in visual studio, works fine , correct things printed console, etc.
when zip , add webjob, api call either not occur, or webjob finishes before occur. when view log after running, see console message "i'm call" occurred, , status changed success , webjob finishes without running of rest of code. webjob not work api call, or doing wrong , there fix? again, i'm new webjobs, simple advice awesome. thanks!
you need wait response happen. calling in "async" methods, static entry point doesn't natively support waiting finish before closing executable. try this:
static void main(string[] args) { program p = new program(); p.makeasync().wait(); } public async task makeasync() { console.writeline("i'm call"); callme c = new callme(); bool x = await c.callbingmapsasync(49931); console.writeline("i called , result {0}", x); }
Comments
Post a Comment