Take the 2-minute tour ×

I'm relatively new to WCF, specifically the WCF 4 REST Online Template.

I am testing a basic method:

[WebGet(UriTemplate = "Test")]
public string Test() 
    return "Test";

The response generated is:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Hello World</string>

Is there any way to send back anything other than XML or JSON, or is there any way to modify the response?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could return Stream; WCF won't apply formatting and you would be free to write whatever content you wanted to the Stream.

This article may help.

Also, keep in mind that if you are going to use this method to serve up a file, for example, then you'll need to find some way to set the MIME type appropriately. This thread should give you some ideas. Personally, I prefer the Registry Read method suggested by @Serguei.

share|improve this answer
Thanks for the link. I will check it out. Does it make more sense to use MVC REST instead of WCF, seeing as how MVC gives you an easier way to control the response? –  XSaint32 Dec 6 '10 at 21:32
@XSaint32. I suppose it depends on taste. I prefer WCF REST for everything rather than MVC REST, but I work with a guy who's exactly the opposite. Our conversations get interesting. :) Also, I've edited my response with a caveat that you'll want to keep in mind if you go WCF. –  Randolpho Dec 6 '10 at 21:43
Thanks for the feedback. I will look into it further. –  XSaint32 Dec 6 '10 at 21:51
add comment

Your Answer


