2012-06-28 22 views
0

我已经创建了一个WCF Web服务,它将适应多种类型的请求(PUT/DELETE/POST/JSON/POX/SOAP)。为此,我针对每个请求风格进行了单独的操作,并使用定义请求类型的属性。因此,如果我有一个名为“WordInfo()”的操作,我会有“WordInfo_POST”,“WordInfo_GETXML()”,“WordInfo_GETJSON()”等。如何将GET/PUT/POST请求指向不同的WCF方法,而不显示这些方法?

问题是,我不希望显示这些额外方法在用户使用客户端应用程序中的WSDL时给用户。换句话说,我不希望他们在intellisense中出现。下面是我在谈论的一个例子:

[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()”公开曝光。

我已经尝试过让操作是私人的,但它要么不会编译,要么不会再接受请求的类型。

谢谢!

回答

0

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

0

REST服务没有WSDL。

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

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

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

相关问题