C# Class WebApiTest.JsonpFormatter

Handles JsonP requests when requests are fired with text/javascript or application/json and contain a callback= (configurable) query string parameter Based on Christian Weyers implementation https://github.com/thinktecture/Thinktecture.Web.Http/blob/master/Thinktecture.Web.Http/Formatters/JsonpFormatter.cs
Inheritance: System.Net.Http.Formatting.JsonMediaTypeFormatter
Exibir arquivo Open project: KHProjects/KH-Parker-Fox Class Usage Examples

Public Methods

Method Description
CanWriteType ( Type type ) : bool
GetPerRequestFormatterInstance ( Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType ) : System.Net.Http.Formatting.MediaTypeFormatter

Override this method to capture the Request object and look for the query string parameter and create a new instance of this formatter. This is the only place in a formatter where the Request object is available.

JsonpFormatter ( ) : System
WriteToStreamAsync ( Type type, object value, Stream stream, HttpContentHeaders contentHeaders, System.Net.TransportContext transportContext ) : System.Threading.Tasks.Task

Override to wrap existing JSON result with the JSONP function call

Private Methods

Method Description
GetJsonCallbackFunction ( HttpRequestMessage request ) : string

Retrieves the Jsonp Callback function from the query string

Method Details

CanWriteType() public method

public CanWriteType ( Type type ) : bool
type System.Type
return bool

GetPerRequestFormatterInstance() public method

Override this method to capture the Request object and look for the query string parameter and create a new instance of this formatter. This is the only place in a formatter where the Request object is available.
public GetPerRequestFormatterInstance ( Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType ) : System.Net.Http.Formatting.MediaTypeFormatter
type System.Type
request System.Net.Http.HttpRequestMessage
mediaType System.Net.Http.Headers.MediaTypeHeaderValue
return System.Net.Http.Formatting.MediaTypeFormatter

JsonpFormatter() public method

public JsonpFormatter ( ) : System
return System

WriteToStreamAsync() public method

Override to wrap existing JSON result with the JSONP function call
public WriteToStreamAsync ( Type type, object value, Stream stream, HttpContentHeaders contentHeaders, System.Net.TransportContext transportContext ) : System.Threading.Tasks.Task
type System.Type
value object
stream Stream
contentHeaders System.Net.Http.Headers.HttpContentHeaders
transportContext System.Net.TransportContext
return System.Threading.Tasks.Task