我在Xamarin android项目中使用Simple.OData.Client。我试图通过用户授权从Lightswitch odata服务访问数据。
获得&插入工作:即FindEntriesAsync()和InsertEntryAsync()。
但是更新/删除方法不起作用,即UpdateEntryAsync()和DeleteEntryAsync()。代码只是挂在await命令上。
// DELETE NOT WORKING
RunOnUiThread(() => phoneNumberText.Text = "Trying to delete existing record.");
await client
.For("JobTypes")
.Key(7)
.DeleteEntryAsync();
returnValue = "Deleted OK";
RunOnUiThread(() => phoneNumberText.Text = returnValue);
// UPDATE - NOT WORKING
RunOnUiThread(() => phoneNumberText.Text = "Trying to update existing record.");
String newJobTypeName = "xxNewJobType2changed";
await client
.For("JobTypes")
.Key(7)
.Set(new { JobType1 = newJobTypeName })
.UpdateEntryAsync();
returnValue = "Updated OK";
RunOnUiThread(() => phoneNumberText.Text = returnValue);
// INSERT - working
Boolean isActive = true;
newJobTypeName = "xxNewJobType2";
RunOnUiThread(() => phoneNumberText.Text = "Trying to insert new record.");
var newJobType = await client
.For("JobTypes")
.Set(new { JobType1 = newJobTypeName, IsActive = isActive })
.InsertEntryAsync();
returnValue = "New JobTypeID = " + newJobType["JobTypeId"];
// GET - working
var terms = await client.FindEntriesAsync("JobTypes");
foreach (var term in terms)
{
returnValue += term["JobType1"];
}
我已经将所有四个例程的代码放在这里。有没有人看到这个或任何人可以给出任何指示?
答案 0 :(得分:1)
这是Simple.OData.Client 3.0中的一个错误,它忽略了If-Match etag。根据{{3}},当发出PUT,MERGE或DELETE请求时,客户端需要在If-Match HTTP请求头中指示ETag。
某些OData服务不会检查If-Match标头,但其他人(Lightswitch)会这样做,而且由于Simple.OData.Client没有设置它们,因此这些服务的更新和删除操作失败。 该错误现已在即将推出的Simple.OData.Client(3.1)版本中修复。