【发布时间】:2012-03-26 16:54:21
【问题描述】:
我想尝试this 自托管 Web 服务的示例(最初用 WCF WebApi 编写),但使用新的 ASP.NET WebAPI(它是 WCF WebApi 的后代)。
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")
};
}
}
}
但是,要么我没有 NuGotten 正确的包,要么 HttpServiceHost 擅离职守。 (我选择了“自托管”变体)。
我错过了什么?
【问题讨论】:
-
This 帮助我完成了一些工作,但它看起来不像是严格的等价物。
标签: c# wcf-web-api asp.net-web-api