gpt4 book ai didi

c# - 为什么这个简单的 RESTful WCF 服务会因 404 错误而失败?

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:49 26 4
gpt4 key购买 nike

使用本教程:

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", 我得到:

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

找不到资源。说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下 URL 并确保其拼写正确。

请求的URL:/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

关于c# - 为什么这个简单的 RESTful WCF 服务会因 404 错误而失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com