简体   繁体   中英

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). 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.

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. 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.

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.

What do you want do achieve then? Anyway user will not see any methods, because no 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.

Or if you do not want client to consume some methods, just do not expose it and remove WebGet, WebInvoke attributes on them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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