I’m trying to change the response to get jsonp(for web services), but the problem is that the write method is never ever called only flush() is called at the end, the url is
localhost:8080/api/employees
its calling web api and employee is a controller file,
Controller Method which is called
public List<Models.Employee> Get() {
var employees = from e in _context.Employees
select new Models.Employee {
Id = e.EmployeeID,
FirstName = e.FirstName,
LastName = e.LastName
};
return employees.ToList();
}
IHTTPModule Method which is invoked
public void OnReleaseRequestState(object sender, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;
if (response.ContentType != JSON_CONTENT_TYPE && response.ContentType != JSON_CONTENT_TYPE1) return;
//response.ContentEncoding =
// char[] c = { 'd', 's', 'w', 'w' };
response.Filter = new JsonResponseFilter(response.Filter);
//response.Cache.
// response.ClearContent();
// response.Write(c, 0, 4);
// response.Flush();
}
Now JsonResponseFilter.write is not called thats the issue, anyone kindly reply back to resolve it
You are doing it all wrong. Don’t use any IHttpModules. The correct way to achieve this in the Web API is to use a custom media formatter. For example there’s a JsonpFormatter that you could integrate in
Application_Startand which will enable JSONP for your web methods: