一直在编写我的第一个 WCF Rest 服务并且进展顺利......但我有一个小问题,有人可以帮忙吗?
当我转到本地电脑上的帮助页面时,就像这样
http://localhost/WcfRestService1/help
它显示以下内容,但 URI 错误,请注意 URI 为空白或仅要求参数 {id}
Uri Method Description
GET Service at http://localhost/WcfRestService1/
POST Service at http://localhost/WcfRestService1/
{id} GET Service at http://localhost/WcfRestService1/{ID}
PUT Service at http://localhost/WcfRestService1/{ID}
DELETE Service at http://localhost/WcfRestService1/{ID}
它真的应该是(见下文我的方法)
Uri
Tasks Get ....
Users/{id} Get ....
这是我的方法,所以 URI 应该显示正确的 URI,请参阅我的属性 UriTemplate
[WebGet(UriTemplate = "Tasks")]
public List<SampleItem> GetCollection()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
}
[WebGet(UriTemplate = "Users/{id}")]
public SampleItem Get(string id)
{
// TODO: Return the instance of SampleItem with the given id
//throw new NotImplementedException();
return new SampleItem() {Id = 1, StringValue = "Hello"};
}