У меня есть ServiceContract, описывающий метод, используемый в службе WCF. Метод имеет атрибут WebGet, который определяет UriTemplate и ResponseFormat.
Я хочу повторно использовать один метод и иметь несколько атрибутов WebGet с разными UriTemplates и различными ResponseFormats. В основном я надеюсь избежать использования нескольких методов, чтобы различать такие вещи, как тип возврата, являющийся XML и JSON. Во всех примерах, которые я видел до сих пор, мне требуется создать другой метод для каждого атрибута WebGet. Здесь пример OperationContract
[ServiceContract]
public interface ICatalogService
{
[OperationContract]
[WebGet(UriTemplate = "product/{id}/details?format=xml", ResponseFormat = WebMessageFormat.Xml)]
Product GetProduct(string id);
[OperationContract]
[WebGet(UriTemplate = "product/{id}/details?format=json", ResponseFormat = WebMessageFormat.Json)]
Product GetJsonProduct(string id);
}
Используя вышеприведенный пример, я хотел бы использовать метод GetProduct для типов возвращаемого типа xml и json следующим образом:
[ServiceContract]
public interface ICatalogService
{
[OperationContract]
[WebGet(UriTemplate = "product/{id}/details?format=xml", ResponseFormat = WebMessageFormat.Xml)]
[WebGet(UriTemplate = "product/{id}/details?format=json", ResponseFormat = WebMessageFormat.Json)]
Product GetProduct(string id);
}
Есть ли способ достичь этого, поэтому я не застрял в написании разных методов, чтобы возвращать разные ResponseFormats?
Спасибо!