Return raw string from REST service method

bzamfir picture bzamfir · Feb 3, 2012 · Viewed 14.4k times · Source

I have a REST service method written in C#, defined as below:

[WebGet(UriTemplate = "/{par1}/{par2}/{par3}")]
public string ProcessGet(string par1, string par2, string par3)
{
    return Execute(...);
}

It should return result as XML or JSON, based on one parameter (I generate the json and XML serialization)

How can I make this method to return the RAW string, just as I created it, without HTMLEncoding it?

Thank you

Answer

carlosfigueira picture carlosfigueira · Feb 3, 2012

Return it as a Stream - that causes the "raw" mode to be used and WCF will not touch your response. You can find more information at http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx.