基本上,我希望像下面这样工作:公共类BookService RestService RestMet

Basically I want something like the following to work -

基本上,我希望像下面这样工作:

 public class BookService : RestService 
{
[RestMethod(Verb="POST", Uri="something")]
public XmlNode MethodOne(string uri, XmlNode input) { }
  [RestMethod(Verb="GET", Pattern="/book/**")] 
public XmlNode MethodTwo(string uri) { }
  [RestMethod(Verb="GET", Pattern="/order/")] 
public XmlNode MethodThree(string uri, NameValueCollection queryString) { }
}

So for MethodOne, only POSTs to the URI "something" will be dispatched to it. And since it has an XmlNode as a parameter, I would check the content type of the incoming request. If it is text/xml (or one of the XML variants like application/soap+xml), I will load it and pass it in.

因此,对于MethodOne,只有URI“内容”的POST才会被分派给它。 并且由于它具有XmlNode作为参数,因此我将检查传入请求的内容类型。 如果它是text / xml(或XML变体之一,例如application / soap + xml),则将其加载并传递。

For MethodTwo, only POSTs to the URI /book/ and all the sub-URIs underneath book will be dispatched to it. Nothing is passed in by default. That does not mean you can't get access to the information. You can get access to the stuff through the Current HttpContext or the helper properties you inherit from RestService.

对于MethodTwo,只有URI / book /以及book下的所有子URI的POST都会被派发到它。 默认情况下,不传递任何内容。 这并不意味着您无法访问该信息。 您可以通过Current HttpContext或从RestService继承的帮助程序属性来访问这些内容。

Finally for MethodThree, it is similar to MethodTwo except that the parameter it takes is NameValueCollection. This is just for convenience. The framework will pass in the query string directly. If MethodThree happened to want handle a POST, then the NameValueCollection would be a combination of Form variables as well as query string. I'm debating whether or not to make that configurable through an attribute. 

最后,对于MethodThree,它与MethodTwo相似,不同之处在于它采用的参数是NameValueCollection。 这只是为了方便。 该框架将直接传递查询字符串。 如果MethodThree碰巧要处理POST,则NameValueCollection将是Form变量和查询字符串的组合。 我正在讨论是否通过属性使它可配置。

[News from the Forest]

[森林新闻]

This will be pretty slick when Justin gets it done...I'm looking a lot into how to implement REST on .NET, as well as how a Message Broker would look for a more SOAP-y document-y world looks.

贾斯汀完成这项工作时,这将非常顺手。我正在研究如何在.NET上实现REST,以及Message Broker如何寻找更像SOAP-y document-y的世界。

翻译自: https://www.hanselman.com/blog/basically-i-want-something-like-the-following-to-work-public-class-bookservice-restservice-restmet

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值