写了我的第一个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"};
}