在我的以下应用程序中,我生成了一个类'JobManager'的列表。
List<JobManager>
访问数据库并填写我的列表是完美的。将此类列表返回给我的客户端似乎存在问题。
详细地说,我的代码看起来像这样
IService Class
OperationContract(Name = "ReadJobQueue")]
[FaultContract(typeof(FaultException))]
List<JobManager> AccessManager(List<string> status,string process, string dtFrom, string dtTo);
Service : IService
public List<JobManager> AccessManager(List<string> status, string process, string dtFrom, string dtTo)
{
//return 'new List<JobManager>()' does work, without any data being filled.
return new JobBuilder(status, process, dtFrom, dtTo);
}
[DataContract]
public class JobManager
{
List<JobManager> _jobManagerchildren = new List<JobManager>();
[DataMember(IsRequired = true, Order = 0)]
public string Description { get; set; }
[DataMember]
public List<JobManager> JobManagerChildren
{
get { return _jobManagerchildren; }
internal set { _jobManagerchildren = value; }
}
}
internal class JobBuilder : List<JobManager>
{
public JobBuilder(List<string> status, string process, string dtFrom, string dtTo)
: base()
{
DataTable dt = new Database().AccessJobQueue(status, process, dtFrom, dtTo);
foreach (DataRow row in dt.Rows)
{
Add(new JobManager { Description = row[1].ToString(), JobManagerChildren = JobDetail(row[0].ToString()) });
}
}
...
}
我错过了JobManager课程的内容吗?
编辑错误代码/异常
System.Net.Sockets.SocketException: remotehost已关闭现有连接 bei System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小 ,SocketFlags socketFlags) bei System.ServiceModel.Channels.SocketConnection.ReadCore(Byte [] buffer,Int 32偏移,Int32大小,TimeSpan超时,布尔结束) --- Ende derinternenAusnahmestapelüberwachung--- bei System.ServiceModel.Channels.SocketConnection.ReadCore(Byte [] buffer,Int 32偏移,Int32大小,TimeSpan超时,布尔结束) bei System.ServiceModel.Channels.SocketConnection.Read(Byte [] buffer,Int32 o ffset,Int32大小,TimeSpan超时) bei System.ServiceModel.Channels.DelegatingConnection.Read(Byte [] buffer,Int 32偏移,Int32大小,TimeSpan超时) bei System.ServiceModel.Channels.ConnectionStream.Read(Byte [] buffer,Int32 o ffset,Int32计数) bei System.Net.FixedSizeReader.ReadPacket(Byte []缓冲区,Int32偏移量,Int32 计数) bei System.Net.Security.NegotiateStream.StartFrameHeader(Byte [] buffer,Int32 offset,Int32 count,AsyncProtocolRequest asyncRequest) bei System.Net.Security.NegotiateStream.ProcessRead(Byte [] buffer,Int32 offs et,Int32 count,AsyncProtocolRequest asyncRequest) --- Ende derinternenAusnahmestapelüberwachung--- bei System.Net.Security.NegotiateStream.ProcessRead(Byte [] buffer,Int32 offs et,Int32 count,AsyncProtocolRequest asyncRequest) bei System.Net.Security.NegotiateStream.Read(Byte [] buffer,Int32 offset,Int 32个数) bei System.ServiceModel.Channels.StreamConnection.Read(Byte [] buffer,Int32 o ffset,Int32大小,TimeSpan超时) --- Ende der internenAusnahmestapelüberwachung---
服务器堆栈跟踪: bei System.ServiceModel.Channels.StreamConnection.Read(Byte [] buffer,Int32 o ffset,Int32大小,TimeSpan超时) bei System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan tim EOUT) bei System.ServiceModel.Channels.SynchronizedMessageSource.Receive(TimeSpan t imeout) bei System.ServiceModel.Channels.FramingDuplexSessionChannel.Receive(TimeSpan) 超时) bei System.ServiceModel.Channels.FramingDuplexSessionChannel.TryReceive(TimeS 平移超时,消息&amp;信息) bei System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message messag e,TimeSpan超时) bei System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean o neway,ProxyOperationRuntime操作,Object [] ins,Object [] outs,TimeSpan ti meout) bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCal) lMessage methodCall,ProxyOperationRuntime operation) bei System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
在[0]处重新抛出异常: bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage re qMsg,IMessage retMsg) bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgD ata,Int32型) bei WcfSys.Shared.IService.AccessManager(List`1 status,String process,S tring dtFrom,String dtTo) WcfSys.Ser中的bei WcfSys.Server.Program.Main() ver \ Program.cs:Zeile 66。
答案 0 :(得分:0)
实际上,您发送回客户端的是List<JobManager>
,但实际上它是派生类。所以有两种方法可以解决这个问题:
JobBuilder
复制到新List<JobManager>
并返回该新列表JobBuilder
DataContract
。作为 - 通过OOP原则 - 知道您返回的对象是JobBuilder
,运行时会尝试序列化JobBuilder
实例。但是,这不是WCF通信的已知类型。