【问题标题】:WCF Service Application returns 404 using WebGetWCF 服务应用程序使用 WebGet 返回 404
【发布时间】:2010-10-25 07:03:38
【问题描述】:

我只创建了最基本的 WCF 服务应用程序来做一些原型设计,但我无法让 WebGet 实现工作。

这是我的界面:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet(UriTemplate = "/rest/{value}")]
    string Test(string value);
}

这是实现:

public string Test(string value)
{
    return string.Format("You entered: {0}", value);
}

但是如果我在浏览器中访问http://localhost:3305/rest/Hello,我会得到 404。我使用的是 VS 2008 网络服务器。

【问题讨论】:

    标签: c# wcf web-services http-status-code-404


    【解决方案1】:

    我认为您缺少实际的服务名称。

    http://localhost:3305/yourservicename.svc/rest/Hello

    【讨论】:

    • 是的 - 不要忘记 URL 中的 SVC 文件!
    • 那行得通。我还必须将结束绑定更改为“webHttpBinding”并创建一个指定 的端点行为——这对于熟悉这些东西的人来说可能是明显的遗漏,但对于 WCF 的新手来说却不容易发现。再次感谢。
    • 您在 Web.Config 中进行了哪些更改以使其与 webHttpBinding 一起使用?
    【解决方案2】:

    更新

    config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    
    public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
             config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
             config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            //config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-20
      • 2014-08-10
      • 2011-01-04
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 2013-03-24
      相关资源
      最近更新 更多