Call a function with a different output

Nov 5 2015 11:38 AM
Goodmorning,
 
I'm trying to realize my 1st project with an WCF service and I've got a question:
I created a web Interface like this:
 
[ServiceContract]
public interface IREST
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "/GetSomething?id={varID}")]
Controllo GetSomething(Int32 varID);
}
And all works: I call the function through the web and I see my XML as a result, perfect!
 
Now the problem: if I want to let the user choose the output (Xml or Json) how I've to do it?
 Atm I changed my code like so:
 
[ServiceContract]
public interface IREST
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "/GetSomethingX?id={varID}")]
Controllo GetSomethingX(Int32 varID);
 
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "/GetSomethingJ?id={varID}")]
Controllo GetSomethingJ(Int32 varID);
 
}
 
 
because if I try to use the same method in different OperationContract it gives me an error.
I've to duplicate every single function to do this? I hope no! 
 

Answers (2)