我想自託管Windows窗體應用程序內的Web API服務使用下面自託管的Web API服務爲Windows窗體
namespace MascoteAquarium.Desktop
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute(
"DefaultApi", "api/{controller}/id", new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMainMenu());
}
}
}
代碼當我嘗試
http://localhost:8080/api/*(some-controller)*
我收到NullReferenceException at System.Web.Http.SelfHost.HttpSelfHostServer.ProcessRequestContext(ChannelContext channelContext,RequestContext requestContext)
有人知道發生了什麼?是否可以在Win Forms應用程序中自行託管?
你設法解決這個問題? – Osi