1
我有一個簡單的類TestController
,它源自ApiController並處理POST
Http請求。我也有上http://localhost:12357
用ApiController連接HttpSelfHostServer
using System;
using System.Net.Http;
using System.ServiceModel;
using System.Web.Http;
using System.Web.Http.SelfHost;
namespace RestController
{
class Program
{
static void Main(string[] args)
{
var config = new HttpSelfHostConfiguration("http://localhost:12357");
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
}
}
public class TestController : ApiController
{
[HttpPost]
public HttpResponseMessage PostMethodFactory()
{
return new HttpResponseMessage();
}
}
}
我試圖找出如何將TestController
連接到HttpSelfHostServer
監聽的HttpSelfHostServer一個實例。我如何使所有POST
請求http://localhost:12357
路由到TestController
類?