I want to use an ajax-based component (KendoUI) to read/modify entities on an OData endpoint implemented by WCF DataServices.
The service implementation was fairly easy in the first place:
public class MyFooService : DataService<FooContext>
{
public static void SetEntitySetAccessRules(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("Foos", EntitySetRights.AllWrite);
}
}
Now I was expecting to be able to modify entities using PUT. KendoUI provides a nice and easy configuration interface and does a good job in generating the PUT request.
We are making a cross-domain request and use CORS. So, Firefox, for example, sends a preflight OPTIONS request to the OData service before sending the PUT.
Unfortunately the service endpoint seems not to support OPTIONS out-of-the-box: The response to the OPTIONS request is "501 Not Implemented" with an empty content. At least we managed that the response has the CORS headers as follows:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!-- Enable cross-origin resource sharing -->
<!-- http://enable-cors.org/#how-asp.net -->
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="POST, PUT, DELETE, GET, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="content-Type, accept, origin, X-Requested-With" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
</system.webServer>
Googling for this has turned out a bit challenging because "options" is a very popular term...
I found this article but it seems very, very complicated. I mean, OData is all about REST, I can't imagine that WCF Data Services don't provide a simple way to allowing preflight requests, or?