WCF、Silverlight 5、自跟踪实体和(反)序列化
我正在开发 Silverlight 应用程序。它使用 WCF 服务在客户端和服务器之间来回传递 EF 4 自跟踪实体。
读取方法工作正常,可以从 WCF 服务向 Silverlight 客户端提供可跟踪实体集合。即使是基本的更新也能正常工作。我可以修改“OfficeEntity”的属性,并将其作为参数传递给 WCF 更新方法。 我们遇到的问题是,当我们更新实体的集合之一时,我们收到以下反序列化错误。例如,如果“OfficeEntity”有一个导航属性“Locations”,它是“LocationEntity”的集合,并且我们向“Locations”属性添加一个新的“Location”并保存它,则会出现反序列化异常。
officeEntity.Locations.Add(new Location() {LocationName = "测试 1"});
client.SaveAsync(officeEntity);
异常详细信息:
格式化程序在尝试反序列化消息时引发异常: 尝试反序列化参数 :OfficeEntity 时出错。 InnerException >消息是 '反序列化 Entities.OfficeEntity 类型的对象时出错。 预计名称空间中的结束元素“ObjectsAddedToCollectionProperties”>“http://schemas.datacontract.org/2004/07/Entities”。 从命名空间 >“http://schemas.datacontract.org/2004/07/Entities”找到元素“b:AddedObjectsForProperty”。
问题似乎出在反序列化更改跟踪属性上。关于造成此问题的原因或我可以在哪里解决它有什么想法吗?
谢谢, 贾森
I am working on a Silverlight applicaiton. It uses WCF services to pass EF 4 Self Tracking Entities back and forth from client to server.
Read methods are working fine to serve the Trackable entity collections to the Silverlight client from the WCF services. Even basic updates are working correctly. I can modify a property of "OfficeEntity", and pass it as a parameter to a WCF update method.
The issue we are having is when we update one of the Entity's collections, we get the below deserialization error. For example, if "OfficeEntity" has a navigation property "Locations" that is a collection of "LocationEntity", and we add a new "Location" to the "Locations" property and save it, we get the deserialization exception.
officeEntity.Locations.Add(new Location() {LocationName = "Test 1"});
client.SaveAsync(officeEntity);
Exception Details:
The formatter threw an exception while trying to deserialize the message:
There was an error while trying to deserialize parameter :OfficeEntity. The InnerException >message was
'There was an error deserializing the object of type Entities.OfficeEntity.
End element 'ObjectsAddedToCollectionProperties' from namespace >'http://schemas.datacontract.org/2004/07/Entities' expected.
Found element 'b:AddedObjectsForProperty' from namespace >'http://schemas.datacontract.org/2004/07/Entities'.'
It appears the problem is with deserializing the change tracking properties. Any ideas on what causes this or where I can fix it?
Thanks,
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果客户端中未使用实际生成的实体,则自我跟踪实体会出现跟踪问题 - 我在博客中介绍了它 此处。
不确定这是否是序列化问题的根源,但肯定会影响您使用自我跟踪实体
Self tracking entities have issues with tracking if the actual generated entities aren't used in the client - I blogged about it here.
Not sure if this is at the root of your serialization issues but will definitely have an impact on you being able to use self-tracking entities