//OnWriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext)
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
{
string uri = HttpContext.Current.Request.Url.Query;
string method = HttpContext.Current.Request.HttpMethod;
if(HttpContext.Current.Request.HttpMethod =="GET")
{
return Task.Factory.StartNew(() =>
{
var writer = new StreamWriter(writeStream);
var query = HttpUtility.ParseQueryString(uri);
string callback = query[CallbackQueryParameter];
writer.Write(callback + "(");
writer.Flush();
base.WriteToStreamAsync(type, value, writeStream, content, transportContext).Wait();
writer.Write(")");
writer.Flush();
});
}
else
{
return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
}
}