gpt4 book ai didi

c# - 将 Web 服务与 EF 一起使用时出现异常

转载 作者:行者123 更新时间:2023-11-30 14:01:46 26 4
gpt4 key购买 nike

我在调用我的网络服务时遇到了这个异常。我在我的服务中使用 EF 并尝试返回由 EF 创建的 POCO 类。有什么想法吗??

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Data.Entity.DynamicProxies.Job_3C04107CB03F22888B19EF7537A795C816D03441852DC37A42729E7542384BBE was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Job(String n, String ns, Job o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write9_GetJobByNumberResponse(Object[] p) at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer13.Serialize(Object objectToSerialize, XmlSerializationWriter writer) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) at System.Web.Services.Protocols.WebServiceHandler.Invoke() --- End of inner exception stack trace ---

好的,我找到了一篇提到将 ProxyCreationEnabled 属性设置为 false 的帖子;我这样做了,现在它工作正常。将此属性设置为 false 的链式 react 是什么

最佳答案

您需要在 EF 上下文中禁用延迟加载和代理创建,否则您的 POCO 作为异常状态实际上是一个无法序列化的 DynamicProxy

This article (存档 here)将提供更多信息。

关于c# - 将 Web 服务与 EF 一起使用时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7739950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com