7
Tôi muốn thử this ví dụ về dịch vụ web tự lưu trữ (ban đầu được viết bằng WCF WebApi), nhưng sử dụng ASP.NET WebAPI mới (là hậu duệ của WCF WebApi).Tương đương với HttpServiceHost trong ASP.NET WebAPI là gì?
using System;
using System.Net.Http;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Microsoft.ApplicationServer.Http;
namespace SampleApi {
class Program {
static void Main(string[] args) {
var host = new HttpServiceHost(typeof (ApiService), "http://localhost:9000");
host.Open();
Console.WriteLine("Browse to http://localhost:9000");
Console.Read();
}
}
[ServiceContract]
public class ApiService {
[WebGet(UriTemplate = "")]
public HttpResponseMessage GetHome() {
return new HttpResponseMessage() {
Content = new StringContent("Welcome Home", Encoding.UTF8, "text/plain")
};
}
}
}
Tuy nhiên, tôi chưa NuGotten gói đúng hoặc HttpServiceHost là AWOL. (Tôi đã chọn biến thể 'tự lưu trữ').
Tôi đang thiếu gì?
[Điều này] (http://code.msdn.microsoft.com/ASPNET-Web-API-Self-Host-30abca12/view/Reviews) đã giúp tôi làm việc gì đó nhưng không giống một tương đương nghiêm ngặt. – Benjol