-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing Callback Exception #28
Comments
Thanks for submitting the issue. Can you move the OData formatter before the JSONP formatter? Formatter selection happens when you create your HttpContent, which may be done by Web API if you don't explicitly return an HttpResponseMessage. This makes it really hard for cases where you may want to change the returned media type. Perhaps the right thing to do here is to have CanWriteType return false whenever the callback is missing. Do you think that might work? The Accept header may not be used in every case. |
Hi Ryan, Thanks for the reply. That idea about the CanWriteType may work I will give it a try later today hopefully. I believe the EntitySetController stuff dynamically adds ODataMediaTypeFormatter or whatever it is called, so I have not found a place to add the JSONP formatter. Regards Richard…. From: Ryan Riley [mailto:[email protected]] Thanks for submitting the issue. Can you move the OData formatter before the JSONP formatter? Formatter selection happens when you create your HttpContent, which may be done by Web API if you don't explicitly return an HttpResponseMessage. This makes it really hard for cases where you may want to change the returned media type. Perhaps the right thing to do here is to have CanWriteType return false whenever the callback is missing. Do you think that might work? The Accept header may not be used in every case. — |
I just added OData 4 endpoints to my OData 3 web service. It now always picks up JsonpMediaTypeFormatter for any OData request, no matter what I do. I tried the code above and it will break the OData json format. Is there any way for OData requests not picking up the JsonpMediaTypeFormatter? Richard |
Make sure the OData JSON formatter is registered before the JSON-P formatter. If that doesn't fix it; I'm not sure. I don't use OData. I also don't use JSON-P; I use CORS. If you can figure out the problem and send a Pull Request, I'll be happy to review and merge it. |
I made the change to the following two functions and it seems working fine. I'm not sure what kind of side-effect it will cause.
|
Hi,
If I have an ODATA (EntitySetController) endpoint that I want to switch between JSONP and JSON via ACCEPT header (application/json-p or application/odata), this formatter will throw an exception complaining about a missing callback parameter.
The issue happens in the GetPerRequestFormatterInstance method. It seems that the content negotiation is happening and this method get called before the check for supported media types. I could be wrong here, but from debugging the source code this seems to be what is happening. I am using Visual Studio 2013, with ODATA 5.6.1 assemblies.
For my own issue I have modified the code in three places.
In the GetPerRequestFormatterInstance
In the CanWriteType method I check if we can write the type back, if it is a ODATA request and the ACCEPT header is "application/odata" then just return false.
Added a new constructor so we can have a default value for the callback, but to be honest I don't think it is required.
I have not forked or submitted these changes as I don't think they will be suitable for everyone. I just wanted you to know that someone else may run into this issue if they have a mix of standard webapi endpoints and EntitySetController endpoints in their service and need to have JSONP as well. Normally I use CORS but I have been told I need to support IE 8 now :(, hence the reason for JSONP.
Regards
Richard...
The text was updated successfully, but these errors were encountered: