簡體   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