【问题标题】:Calling a Webservice based on Routing from browser URL从浏览器 URL 调用基于路由的 Web 服务
【发布时间】:2015-10-09 17:58:45
【问题描述】:

我创建了一个基本 Web 服务,它根据 DTO 中定义的路由被调用。这是我的示例路由代码..

[Route("/students", Verbs = "GET")] 
[Route("/students/{id}", Verbs = "GET")]
public class StudentRequestDto
{
    public int Id { get; set; }
}

现在,当我通过http://localhost:1661/Students URL 直接调用此网络服务时,我能够得到响应,而当我尝试通过http://localhost:1661/Students?id=1 调用它时,我得到NullReferenceException

我第二次通过http://localhost:1661/Students?id=1 URL 调用服务的方式是否正确,如果不是正确的方式是什么..谢谢。

【问题讨论】:

    标签: .net web-services routing


    【解决方案1】:
    [Route("/students/{id}", Verbs = "GET")]
    

    只匹配:

    http://localhost:1661/students/1
    

    【讨论】:

      猜你喜欢
      • 2013-01-14
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2016-10-24
      • 2010-10-20
      • 2012-04-17
      相关资源
      最近更新 更多