简体   繁体   English

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

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

I have created a WCF Web service that will accommodate several types of requests (PUT/DELETE/POST/JSON/POX/SOAP). 我创建了一个WCF Web服务,该服务将容纳几种类型的请求(PUT / DELETE / POST / JSON / POX / SOAP)。 To do this, I made a separate operation for each request flavor, with attributes that define the request type. 为此,我对每种请求类型进行了单独的操作,并使用定义请求类型的属性。 So if I have an operation named "WordInfo()", I would have "WordInfo_POST", "WordInfo_GETXML()", "WordInfo_GETJSON()", etc. 因此,如果我有一个名为“ WordInfo()”的操作,则将具有“ WordInfo_POST”,“ WordInfo_GETXML()”,“ WordInfo_GETJSON()”等。

The problem is that I would prefer not to show these additional methods to the user when they consume the WSDL in their client applications. 问题在于,当用户在其客户端应用程序中使用WSDL时,我不希望向用户显示这些其他方法。 In other words, I don't want them showing up in intellisense. 换句话说,我不希望它们出现在智能感知中。 Here's an example of what I'm talking about: 这是我正在谈论的示例:

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

But in this example, I would only want "WordInfo()" exposed publicly. 但在此示例中,我只希望公开显示“ WordInfo()”。

I have tried making operations private, but it either won't compile or won't accept the type of request anymore. 我曾尝试将操作设为私有,但它要么不会编译,要么将不再接受请求的类型。

Thanks! 谢谢!

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

There is no WSDL for REST service. 没有用于REST服务的WSDL。

What do you want do achieve then? 那你想实现什么? Anyway user will not see any methods, because no WSDL. 无论如何,用户将看不到任何方法,因为没有WSDL。

Yes for REST services exists 'help' page, you can disable standart help page and make your own and describe there only methods you want to expose. 是,因为REST服务存在“帮助”页面,您可以禁用标准的帮助页面并创建自己的页面,并仅在其中描述您要公开的方法。

Or if you do not want client to consume some methods, just do not expose it and remove WebGet, WebInvoke attributes on them 或者,如果您不希望客户端使用某些方法,则不要公开它并删除它们上的WebGet,WebInvoke属性

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

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