如何限定某个方法只能采用GET或POST方式调用?

forDream_ 2011-01-25 04:50:25
C#写个WebService、其中有些方法我希望只能通过POST方式调用、然而其中一些个别的、我希望能够通过GET方式调用、
这应该如何设置呢?
...全文
220 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
guyehanxinlei 2011-01-31
  • 打赏
  • 举报
回复
支持2楼
flyerwing 2011-01-27
  • 打赏
  • 举报
回复
2楼大虾说的好象对!
bestdowt1314 2011-01-27
  • 打赏
  • 举报
回复
在方法上加 [WebInvoke(UriTemplate = "", Method = "POST")]
机器人 2011-01-27
  • 打赏
  • 举报
回复
Post: [WebInvoke(UriTemplate = "", Method = "POST")]
Get: [WebGet(UriTemplate = "")]
Put: [WebInvoke(UriTemplate = "{id}", Method = "PUT")]
Delete: [WebInvoke(UriTemplate = "{id}", Method = "DELETE")]


[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class Service1
{
// TODO: Implement the collection resource that will contain the SampleItem instances

[WebGet(UriTemplate = "")]
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" } };
}

[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
// TODO: Add the new instance of SampleItem to the collection
throw new NotImplementedException();
}

[WebGet(UriTemplate = "{id}")]
public SampleItem Get(string id)
{
// TODO: Return the instance of SampleItem with the given id
throw new NotImplementedException();
}

[WebInvoke(UriTemplate = "{id}", Method = "PUT")]
public SampleItem Update(string id, SampleItem instance)
{
// TODO: Update the given instance of SampleItem in the collection
throw new NotImplementedException();
}

[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
public void Delete(string id)
{
// TODO: Remove the instance of SampleItem with the given id from the collection
throw new NotImplementedException();
}

}

dna_xp 2011-01-26
  • 打赏
  • 举报
回复
webinvoke这个属性吧,我也不确定

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧