繁体   English   中英

为什么此简单的RESTful WCF服务失败并显示404错误?

[英]Why does this simple RESTful WCF Service fail with a 404 error?

使用本教程:

http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

从VS 2010运行应用程序时,我可以显示要显示的目录列表。

我可以将VS调用的IE浏览器中显示的URL(http:// localhost:4841 /)粘贴到IE的VS外部实例中,然后看到相同的内容。 但是,如果我按照教程中的说明附加“ / xml / 123”或“ / json / 123”,则URI为“ http:// localhost:4841 / xml / 123”或“ http:// localhost: 4841 / json / 123“,我得到:

*“ /”应用程序中的服务器错误。

无法找到该资源。 说明:HTTP404。您正在寻找的资源(或其依赖项之一)可能已被删除,名称更改或暂时不可用。 请查看以下网址,并确保其拼写正确。

要求的网址:/ json / 123 /

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272 *

如果将“ RestServiceImpl.svc”附加到URI,因此它是“ http:// localhost:4841 / RestServiceImpl.svc”,则会得到“服务”页面(“这是Windows©Communication Foundation服务。该服务当前被禁用。“); 但附加“ / xml / 123”或“ / json / 123”会导致相同的404。

最相关的代码(直接取自5星级教程)是:

[ServiceContract]
public interface IRestServiceImpl
{
    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Xml,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "xml/{id}")]
    string XMLData(string id);

    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "json/{id}")]
    string JSONData(string id);
}

我认为您缺少实际的服务,例如。 RestServiceImpl.svc

因此,它将类似于:

http://localhost:35798/ RestServiceImpl.svc /xml/123

好的,我通过在Web.config中替换以下内容来解决了这个难题:

<service name="RestService.RestServiceImpl"

...有了这个:

<service name="REST_JSON_POC.RestServiceImpl"

(以及“ RestService”和“ REST_JSON_POC”一起出现的其他位置)

(“ RestService”是本教程的内容,但是REST_JSON_POC是我的项目的名称)

但是现在我有另一个问题,我将为其创建一个新问题(“ xml / 123”现在可以正常工作,但是“ json / 123”提示下载名为“ 123”的文件,其中包含预期的字符串) 。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM