2

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?

dotariel
  • 1,584
  • 12
  • 23

1 Answers1

1

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.

Edit:
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.

Community
  • 1
  • 1
Randolpho
  • 55,384
  • 17
  • 145
  • 179
  • 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? – dotariel Dec 06 '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 06 '10 at 21:43