找不到八个WCF REST端点中的两个的可能原因?

时间:2013-08-05 05:20:41

标签: wcf rest uri wcf-endpoint

知道最后两个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方法有什么不同。

成功获取位置ID = 2的测试网址

GET http://localhost:57004/AppsService.svc/v1/locations/2

返回正确的JSON:

{
    "Id": 2,
    "Identifier": "L85",
    "Name": "The Huge Lake",
    "Signals": null
}

以下是测试网址,尝试从位置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);
    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

发现问题:我。

在调试端点#6之后,我将项目的OutputPath属性从默认的“bin”更改为“$(SolutionDir)\ $ Configuration”,这是我们用于所有项目的模式。

事实证明,当您从VS调试Web项目时,它总是在通过IIS或Cassini独立Web服务器启动项目时查找程序集的相对“bin \”文件夹。项目的OutputPath属性在没有投诉的情况下被忽略。

所以我不得不调试我的程序集的陈旧版本,它只包含前6个端点的路由。