WCF Service Application returns 404 using WebGet

痴心易碎 提交于 2019-12-24 00:48:48

问题


I created just the most basic WCF Service Application to do some prototyping, but I can't get the WebGet implementation to work.

Here's my interface:

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

Here's the implementation:

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

But if I go to http://localhost:3305/rest/Hello in my browser, I get a 404. I'm using the VS 2008 webserver.


回答1:


I think your missing the actual service name.

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




回答2:


Update

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;
    }


来源:https://stackoverflow.com/questions/848198/wcf-service-application-returns-404-using-webget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!