使用REST的webinvoke或webget时,可以忽略WCF [operationcontract]吗?

时间:2013-02-05 04:18:27

标签: c# wcf rest

[WebInvoke(UriTemplate = "/GetContent", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public List<Content> GetContent(string path) {
        return Utility.GetContent(path);
    }

[OperationContract]
[WebInvoke(UriTemplate = "/GetContent", RequestFormat = WebMessageFormat.Json,     BodyStyle = WebMessageBodyStyle.Wrapped)]
public List<Content> GetContent(string path) {
    return Utility.GetContent(path);
}

这两种方法的功能是否相同,或者它们做了哪些不同的事情?看起来他们都适合我..

1 个答案:

答案 0 :(得分:0)

OperationContractAttribute属性声明方法是服务合同中的操作。只有使用OperationContractAttribute的方法才会公开为服务操作。没有任何标记有OperationContractAttribute的方法的服务合同不会公开任何操作。