c# - Cannot start an Azure WebJob command line application (Pending restart status) -
this first time trying develop , deploy self hosted owin web api application in microsoft azure. question's sake want try , deploy sample application found here.
so have 3 files, program.cs, startup.cs, , valuescontroller.cs:
program.cs
using microsoft.owin.hosting; using system; namespace owinselfhostsample { public class program { static void main() { string baseaddress = "http://<mysitename>.azurewebsites.net/"; // start owin host using (webapp.start<startup>(url: baseaddress)) { console.readline(); } } } }
startup.cs
using owin; using system.web.http; namespace owinselfhostsample { public class startup { // code configures web api. startup class specified type // parameter in webapp.start method. public void configuration(iappbuilder appbuilder) { // configure web api self-host. httpconfiguration config = new httpconfiguration(); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); appbuilder.usewebapi(config); } } }
valuescontroller.cs
using system.collections.generic; using system.web.http; namespace owinselfhostsample { public class valuescontroller : apicontroller { // api/values public ienumerable<string> get() { return new string[] { "value1", "value2" }; } } }
so when go project , select 'publish azure webjob' says succesfully published .azurewebsites address, yet when navigate http://.azurewebsites.net/api/values receive message: "the resource looking has been removed, had name changed, or temporarily unavailable.".
if run locally , change baseaddress in program.cs localhost works fine , response controller.
the classic azure portal says web job 'pending restart'.
i tried creating webjob project rather console application , tried in program.cs , publishing did not work:
public static void main() { string baseaddress = "http://<mysitename>.azurewebsites.net/"; var host = new jobhost(); // following code ensures webjob running continuously using (webapp.start<startup>(url: baseaddress)) { host.runandblock(); } }
how can have self hosted web api server continuously running?
i think may misunderstanding webjobs for. performing background work (see doc, , not exposing web api. need using regular web app instead.
and note azure web apps go through iis, you'll need use httpplatformhandler (but that's bit of different topic).
Comments
Post a Comment