0

我创建了一个 WCF Web 服务,它将容纳多种类型的请求 (PUT/DELETE/POST/JSON/POX/SOAP)。为此,我为每个请求风格进行了单独的操作,并使用定义请求类型的属性。因此,如果我有一个名为“WordInfo()”的操作,我将有“WordInfo_POST”、“WordInfo_GETXML()”、“WordInfo_GETJSON()”等。

问题是当用户在其客户端应用程序中使用 WSDL 时,我不希望向用户显示这些附加方法。换句话说,我不希望它们出现在智能感知中。这是我正在谈论的一个例子:

[ServiceContract]
interface IWVLibrary
{
    [OperationContract]
    [WebGet(UriTemplate = "WordInfo/{Data}/{ApiKey}?format=xml", ResponseFormat = WebMessageFormat.Xml)]
    [return: MessageParameter(Name = "WordInfo")]
    WordInfoResult WordInfo_GETXML(string data, string ApiKey);

    [OperationContract]
    [WebGet(UriTemplate = "WordInfo/{Data}/{ApiKey}?format=json", ResponseFormat = WebMessageFormat.Json)]
    [return: MessageParameter(Name = "WordInfo")]
    WordInfoResult WordInfo_GETJSON(string Data, string ApiKey);

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    [return: MessageParameter(Name = "WordInfo")]
    WordInfoResult WordInfo_POST(string Data, string ApiKey);

    [OperationContract]
    [WebInvoke(Method = "PUT", UriTemplate = "", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    [return: MessageParameter(Name = "WordInfo")]
    WordInfoResult WordInfo_PUT(string Name, string ApiKey);

    [OperationContract]
    [WebInvoke(Method = "DELETE", UriTemplate = "WordInfo/{Data}/{ApiKey}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    [return: MessageParameter(Name = "WordInfo")]
    WordInfoResult WordInfo_DELETE(string Data, string ApiKey);

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
    WordInfoResult WordInfo(string Data, string ApiKey);
}

但在这个例子中,我只希望“WordInfo()”公开。

我尝试将操作设为私有,但它要么无法编译,要么不再接受请求的类型。

谢谢!

4

2 回答 2

0

REST 服务没有 WSDL。

那你想实现什么?无论如何,用户不会看到任何方法,因为没有 WSDL。

是的,对于 REST 服务存在“帮助”页面,您可以禁用标准帮助页面并制作自己的帮助页面,并在那里仅描述您想要公开的方法。

或者,如果您不希望客户端使用某些方法,请不要公开它并删除它们上的 WebGet、WebInvoke 属性

于 2012-07-01T07:33:01.333 回答
0

我认为您应该使用WebAPI,它适合您的需求。

于 2012-06-28T16:12:49.133 回答