知道为什么没有找到最后两个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条"Endpoint not found"WCF框架消息进行响应。所有8个路由都是GET方法,我已经向Fiddler验证了我确实在使用GET动词。我看不出与其他仍在工作的REST方法有什么不同。
成功获取位置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 获取所有"Visit"对象
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);
}
}
有什么想法吗?
发现问题:me.
调试完端点#6后,我将项目的OutputPath属性从默认的"bin"更改为"$(SolutionDir)\$Configuration)",这是我们所有项目都使用的模式。
事实证明,当您从VS调试web项目时,当它通过IIS或Cassini独立web服务器启动项目时,它总是在相对的"bin\"文件夹中查找程序集。该项目的OutputPath属性被忽略,没有任何抱怨。
因此,我只能调试程序集的一个过时版本,该版本只包含到前6个端点的路由sheesh