如何序列化 SubSonic 生成的类?
我正在尝试将 SubSonic 与 WCF 一起使用。我可以将数据放入列表中,但无法将该数据返回到客户端,其错误是
套接字连接已被释放。对象名称: 'System.ServiceModel.Channels.SocketConnection'。
我尝试通过 POCO 对象向 WCF 发送和检索数据,它可以工作,但是当我尝试使用 SubSonic 生成的类时,它不再工作,所以我认为它有一些问题。
I'm trying to use SubSonic with WCF. I can get data into List but I can't return that data to client side, its error is
The socket connection has been disposed. Object name:
'System.ServiceModel.Channels.SocketConnection'.
I try to send and retrieve data to/from WCF by POCO object and it working but when I try to use generated class from SubSonic it don't work anymore, so I think its has some problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这不是“真正的”例外。我对 WCF 不熟悉,但也许你在日志中找到了一些东西。
这是一篇关于调试 WCF 的文章 http://www.codeproject.com/KB/WCF /DebugWCFApps.aspx
最有可能的是,WCF 正在尝试序列化具有可为 null 属性的 SubSonic 类。
SubSonic 类的属性被标记为 XMLAttribute,如果您想要序列化可为 null 的类型,则会引发错误。 Nullable 只能序列化为 XMLElement。
尝试它是否适用于没有可为 null 属性的 SubSonic 生成的类。
I would assume that this is not the "real" exception. I am not familiar with WCF but maybe you find something in the logs.
Here is an article about debugging WCF http://www.codeproject.com/KB/WCF/DebugWCFApps.aspx
Most likely WCF is trying to serialize a SubSonic class with nullable properties.
Properties of SubSonic classes are marked as XMLAttribute, which throws an error if you want to serialize a nullable type. Nullables can only be serialized as XMLElements.
Try if it works with a SubSonic generated class that has no nullable property.
当我下载了 SubSonic 的源代码并调试到 SubSonic.Core 后,我发现它出错了,因为 GetBody<>将创建该类的实例,并在其构造函数内尝试连接到数据库,但它无法连接;客户端无权访问数据库。
现在我正在努力使用 SubSonic 创建映射类并返回 POCO。
After I've downloaded source code of SubSonic and debug into it SubSonic.Core, I found that it error because GetBody<> will create instance of that class, and inside its constructor is trying to connect to database which it can't; client has no access to database.
Now I'm working on create mapping class with SubSonic and return POCO instead.