【问题标题】:Exception when making a call to DB and returning a List<T>调用 DB 并返回 List<T> 时出现异常
【发布时间】:2012-01-11 11:47:36
【问题描述】:

我正在创建一个连接到数据库并返回结果的 WCF 服务。四分之一的 DataContracts 没有问题(返回一个 int),但其他三个给了我一个异常(返回一个 List)。错误信息下方。

底层连接已关闭:连接意外关闭。

服务器堆栈跟踪:在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest 请求, HttpAbortReason abortReason)
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 超时)在 System.ServiceModel.Channels.RequestChannel.Request(消息消息, TimeSpan 超时)在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息 消息,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannel.Call(字符串动作, Boolean oneway, ProxyOperationRuntime 操作, Object[] ins, Object[] 出局,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime 操作)在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 留言)

在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(消息数据& msgData,Int32 类型)在 IReceiverService.SatList() 在 ReceiverServiceClient.SatList()

内部异常:底层连接已关闭:连接 意外关闭。在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 超时)

【问题讨论】:

    标签: wcf


    【解决方案1】:

    你可能需要用known type attributes装饰返回的实体或服务

    【讨论】:

    • 我检查了链接,但仍然无法修复错误。简单地我添加了一个 [KnowType(typeof(T))] 并且我尝试了 [knowType (name = "T")],两者都在实现接口 (DataContract) 的类中。但是当我尝试运行它时它仍然给我一个错误。
    • 我搜索了,我唯一理解的是 WCF 服务无法理解数据库中表的类型。它无法理解自定义类型!如果我通过 .net 框架返回任何已知类型,它将毫无问题地工作。诠释。请告诉我如何解决这个问题。
    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    相关资源
    最近更新 更多