0

I am trying to create a Windows Store App using a WebApi Odata controller. After some effort I have all the Get requests working, I am now moving onto the CRUD methods, and am getting the following Exception on the EndSaveChanges of the Data Service Context.

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code />
  <m:message xml:lang="en-US">No HTTP resource was found that matches the request URI 'http://localhost:56317/odata/ESFClients(guid'f04ad636-f896-4de4-816c-388106cd39ce')'.</m:message>
  <m:innererror>
    <m:message>No routing convention was found to select an action for the OData path with template '~/entityset/key'.</m:message>
    <m:type></m:type>
    <m:stacktrace></m:stacktrace>
  </m:innererror>
</m:error>

Now I think this is a bug in WebApi from this http://aspnetwebstack.codeplex.com/workitem/822 and its hiding the actual error. To make sure it wasn't my Odata Endpoint I created a quick console app to get an entry, update it and Patch it back, which worked all ok. My WebApi Odata Controller derives from ODataController with
public HttpResponseMessage Patch([FromODataUri] Guid key, Delta<ESFClient> patch) As the method. In my windows application I have a extension method on the DataServiceContext for the Save Changes.

 public static async Task<DataServiceResponse> SaveChangesAsync(this DataServiceContext context, SaveChangesOptions options)
        {
            var queryTask = Task.Factory.FromAsync<DataServiceResponse>(context.BeginSaveChanges(options, null, null),
                   queryAsyncResult =>
                   {
                       var results = context.EndSaveChanges(queryAsyncResult);
                       return results;
                   });

            return await queryTask;
        }

And calling the update like so from a blank Windows Store XAML page.

 public async Task UpdateWeekNo()
        {
            var container = new ESFOdataService.Container(new Uri("http://localhost:56317/odata/"));
            var clients = (DataServiceQuery<ESFClient>)from p in container.ESFClients where p.UserID == new Guid("f04ad636-f896-4de4-816c-388106cd39ce") select p;
            var result = await clients.ExecuteAsync();
            var updatedClient = result.Single();
            if (updatedClient != null)
            {
                updatedClient.WeekNo = 19;
                container.UpdateObject(updatedClient);
                await container.SaveChangesAsync(SaveChangesOptions.PatchOnUpdate);  // Use PATCH not MERGE.
            }           
        }

So does anyone come across the same issue, or know how I can find out the actual error. One interesting point is that if I debug the controller while running the Windows App, the patch method does not get called.

1 Answers1

0

Ok, so I have finally solved this. Just a recap for those who could experience the same issue. I have an Odata WebApi controller, Windows 8 Store Application using WCF Client Library, with the reference created from Add Service Reference. When trying to update (patch) a record an exception was being thrown at the EndSaveChanges. This is because for some reason Post Tunneling is enabled by default on my context. Setting this to false allowed everything to work.

Context.UsePostTunneling = false;
Context.IgnoreResourceNotFoundException = true;