I’m starting my very first REST service with WCF:
var host = new ServiceHost(typeof(Service), new System.Uri(address));
var binding = new WebHttpBinding();
var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IService)), binding, new EndpointAddress(address + "rest"));
host.Description.Endpoints.Add(endpoint);
host.Open();
IService defines a few methods that return JSON data and it is Ok. But is there a some way to return plain text or HTML or binary data?
You can return a Stream and set WebOperationContext.Current.OutgoingResponse.ContentType to the content type you are returning. Here is an MSDN example: http://msdn.microsoft.com/en-us/library/cc681221.aspx