这是我第一次尝试在Microsoft Azure中开发和部署自托管的OWIN Web API应用程序。为了问题的缘故,我想尝试部署示例应用程序here。无法启动Azure WebJob命令行应用程序(等待重启状态)
所以我只是有我的三个文件,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
{
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for 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
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
}
所以,当我去我的项目,并选择“发布为Azure的WebJob”它说,它成功地被发布到.azurewebsites地址,但是当我浏览到http://.azurewebsites.net/api/值我收到消息:“您正在寻找的资源已被删除,名称已更改,或暂时不可用。”
如果我在本地运行并将Program.cs中的baseAddress更改为localhost,则它可以正常工作,并且可以从控制器获得响应。
经典的天青门户说我的网络工作是'等待重启'。
我还试图建立一个WebJob项目,而不是一个控制台应用程序,并在我的Program.cs出版试过,但这个也没有工作:
public static void Main()
{
string baseAddress = "http://<MYSITENAME>.azurewebsites.net/";
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
using (WebApp.Start<Startup>(url: baseAddress))
{
host.RunAndBlock();
}
}
我怎么能有我自己托管的Web服务器API连续运行?