I've use the jsonp formatter described in this blog post: http://www.west-wind.com/weblog/posts/2012/Apr/02/Creating-a-JSONP-Formatter-for-ASPNET-Web-API
Has anybody tried using the formatter with a self hosted console application?
I've tried the formatter in a regular MVC 4 project, and it worked immediately. However, I would like to use it in a self hosted console application, and I've had a lot of trouble getting it to work.
I've registered the formatter, and verified that it is added:
var config = new HttpSelfHostConfiguration(serviceUrl);
config.Formatters.Insert(0, new JsonpMediaTypeFormatter());
I have verified that the formatter is being called when I make a request with the following code:
$("#TestButton").click(function () {
$.ajax({
url: 'http://localhost:8082/Api/Test',
type: 'GET',
dataType: 'jsonp',
success: function(data) {
alert(data.TestProperty);
}
});
})
I've checked in Fiddler, and the response I get is:
HTTP/1.1 504 Fiddler - Receive Failure
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 09:30:51.813
[Fiddler] ReadResponse() failed: The server did not return a response for this request.
I'd be really grateful if anybody can shed some light on what is going on!
Thanks,
Francis