知道为什么最后两个 URI 模板报告找不到端点吗?
v1/version
v1/locations/{id}
v1/locations/{id}/signals
v1/locations&q={searchText}
v1/locations/signals/{signalIds}
v1/signals/{id}
v1/locations/{id}/visits
v1/locations/{locationId}/visits/{id}
所有之前的 6 条路由都可以正常工作,但是当我添加最后 2 条路由时,它们会以 404“未找到端点”WCF 框架消息进行响应。所有 8 条路由都是 GET 方法,我已经用 Fiddler 验证了我确实在使用 GET 动词。我看不出与其他仍在工作的 REST 方法有什么不同。
成功获取 Location Id=2 的测试 URL
GET http://localhost:57004/AppsService.svc/v1/locations/2
返回这个正确的 JSON:
{
"Id": 2,
"Identifier": "L85",
"Name": "The Huge Lake",
"Signals": null
}
这是一个测试 URL,它尝试从 Location ID=2 获取所有“访问”对象
GET http://localhost:57004/AppsService.svc/v1/locations/2/visits
该 URL 失败并出现 404 框架异常:
<HTML>
<HEAD>
<STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px}</STYLE>
<TITLE>Service</TITLE>
</HEAD>
<BODY>
<DIV id="content">
<P class="heading1">Service</P>
<BR/>
<P class="intro">Endpoint not found.</P>
</DIV>
</BODY>
</HTML>
这是完整的服务接口代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using WebAppsService.Models;
namespace WebAppsService
{
[ServiceContract]
public interface IAppsService
{
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/version")]
string GetVersion();
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/locations/{id}")]
Location GetLocation(string id);
// DCSR-specific Location APIs
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/locations/{id}/signals")]
List<Signal> GetLocationSignals(string id);
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/locations&q={searchText}")]
List<Location> GetLocations(string searchText);
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/locations/signals/{signalIds}")]
List<Location> GetLocationsContainingSignals(string signalIds);
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/locations/{id}/visits")]
List<Visit> GetVisits(string id);
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/locations/{locationId}/visits/{id}")]
Visit GetVisit(string locationId, string id);
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "v1/signals/{id}")]
Signal GetSignal(string id);
}
}
有任何想法吗?