Reputation: 2569
I got a web-service and want to return this "string" as a bare string, without the extra serialization by WCF, because it's already serialized.How do I do it?
[OperationContract]
[FaultContract(typeof(Exception))]
[WebGet(ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json)]
string Get_Json();
Upvotes: 2
Views: 812
Reputation: 2262
A much better and cleaner solution seems to be this well documented and cleanly designed project https://github.com/mikeobrien/WcfRestContrib which aims to plug some of the existing holes in the WCF REST solution space. This package is available also through NuGet with:
PM> Install-Package wcfrestcontrib
Upvotes: 0
Reputation: 21015
add a servic/operation behavior that overrides the serializer.. and do nothing in it... just return the result as is
Upvotes: 0
Reputation: 5670
I have found the solution for this on this page. The following should work:
[OperationContract]
public Stream Get_Json() {
return new MemoryStream(Encoding.UTF8.GetBytes("This is a string"));
}
Upvotes: 1