繁体   English   中英

如何将GET / PUT / POST请求定向到不同的WCF方法,而不显示这些方法?

[英]How to direct GET/PUT/POST requests to different WCF methods, without showing those methods?

我创建了一个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()”。

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

谢谢!

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

没有用于REST服务的WSDL。

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

是,因为REST服务存在“帮助”页面,您可以禁用标准的帮助页面并创建自己的页面,并仅在其中描述您要公开的方法。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM