我已经下载并使用了一个DataServiceProvider
的例子,非常基本和常见的"hello world"(一个与Product
和Category
实体)。我正在使用最新的Microsoft.Data.Services
包。
我已经建立了一个客户端来反对它,它工作。GET
请求返回Category
,我编辑它并调用SaveChanges()
来更新。
当我决定将代码从"hello world"虚拟环境移动到IIS上现有的大型应用程序时,更新停止工作。我说的是相同的代码——客户机和服务器!
GET
工作正常,但SaveChanges()
响应抛出异常:
<?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">Content-Type header value missing.</m:message></m:error>
虽然我可以清楚地看到在fiddler,我确实发送了一个Content-Type
头:"Content-Type: application/atom+xml"
var sessionedUri = new Uri("http://myapp/odata.svc/", UriKind.Absolute);
_oDataContext = new DemoService(sessionedUri);
_oDataContext.MergeOption = MergeOption.OverwriteChanges;
Category cate = _oDataContext.CreateQuery<Category>("Categories").FirstOrDefault();
_oDataContext = new DemoService(sessionedUri);
cate.Name = "somethin";
_oDataContext.AttachTo("Categories", cate);
_oDataContext.UpdateObject(cate);
_oDataContext.SaveChanges();
如上所述:
httphandler会介入通信,尽管我发送了消息头,但它可能会删除消息头。由于埃里克