TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Andrea Mariotti
NA
3
769
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!
Reply
Answers (
2
)
WCF Xml Serialization
Issue in production server