WebApi Odata 컨트롤러를 사용하여 Windows Store App을 만들려고합니다. 어떤 노력을 한 후에 Get 요청이 모두 작동하고 CRUD 메서드로 옮겨 가고 데이터 서비스 컨텍스트의 EndSaveChanges에서 다음과 같은 예외가 발생합니다. WebApi Odata Windows Store App EndSaveChanges 예외
<?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>
는 지금 문제는이
http://aspnetwebstack.codeplex.com/workitem/822와 실제 오류를 숨기고에서 WebApi의 버그라고 생각합니다. 내 오다타 엔드 포인트가 아니 었는지 확인하기 위해 엔트리를 얻고 업데이트하고 다시 패치하는 빠른 콘솔 앱을 만들었습니다. 내 WebApi Odata 컨트롤러는 ODataController에서 파생됩니다.
public HttpResponseMessage Patch([FromODataUri] Guid key, Delta<ESFClient> patch)
방법으로. 내 Windows 응용 프로그램에서 Save Changes에 대한 DataServiceContext에 대한 확장 메서드가 있습니다.
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;
}
빈 Windows Store XAML 페이지 에서처럼 업데이트를 호출하십시오.
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.
}
}
누구든지 동일한 문제를 겪거나 실제로 오류를 발견 할 수있는 방법을 알고 있습니다. 한 가지 흥미로운 점은 Windows 응용 프로그램을 실행하는 동안 컨트롤러를 디버깅하면 패치 메서드가 호출되지 않는다는 것입니다.
오류의 원인은 모르지만 확장 방법은 간단합니다 (http://pastebin.com/iJa2ksY0). –