-1

在我的以下应用程序中,我生成了“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:现有连接已被远程主机关闭,位于 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size , SocketFlags socketFlags) bei System.ServiceModel.Channels.SocketConnection .ReadCore(Byte[] buffer, Int 32 offset, Int32 size, TimeSpan timeout, Boolean close) --- Ende der internen Ausnahmestapelüberwachung --- bei System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int 32 offset , Int32 大小, TimeSpan 超时, 布尔关闭) bei System.ServiceModel.Channels.SocketConnection.Read(Byte[] 缓冲区, Int32 偏移量, Int32 大小, TimeSpan 超时) bei System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int 32 offset, Int32 size, TimeSpan timeout) bei System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer,Int32 offset, Int32 count) bei System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) 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 der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[ ] 缓冲区,Int32 偏移量,Int32 大小,TimeSpan 超时)--- Ende der internen Ausnahmestapelüberwachung ---Int32 count) bei System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) 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 der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o 偏移量、Int32 大小、TimeSpan 超时)--- Ende der internen Ausnahmestapelüberwachung ---Int32 count) bei System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) 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 der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o 偏移量、Int32 大小、TimeSpan 超时)--- Ende der internen Ausnahmestapelüberwachung ---ReadPacket(Byte[] buffer, Int32 offset, Int32 count) 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 der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) - -- Ende der internen Ausnahmestapelüberwachung ---ReadPacket(Byte[] buffer, Int32 offset, Int32 count) 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 der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) - -- Ende der internen Ausnahmestapelüberwachung ---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 der internen Ausnahmestapelüberwachung --- 在 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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o ffset, Int32 size, TimeSpan timeout) --- Ende der internen Ausnahmestapelüberwachung ---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 der internen Ausnahmestapelüberwachung --- 在 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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o ffset, Int32 size, TimeSpan timeout) --- Ende der internen Ausnahmestapelüberwachung ---Int32 offs et, Int32 count, AsyncProtocolRequest asyncRequest) --- Ende der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o ffset, Int32 size, TimeSpan timeout) --- Ende der实习生 Ausnahmestapelüberwachung ---Int32 offs et, Int32 count, AsyncProtocolRequest asyncRequest) --- Ende der internen Ausnahmestapelü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 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o ffset, Int32 size, TimeSpan timeout) --- Ende der实习生 Ausnahmestapelüberwachung ---Int 32 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) --- Ende der internen Ausnahmestapelüberwachung ---Int 32 count) bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) --- Ende der internen Ausnahmestapelüberwachung ---

服务器堆栈跟踪:bei System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 o ffset, Int32 size, TimeSpan timeout) bei System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan time eout) bei System.ServiceModel。 Channels.SynchronizedMessageSource.Receive(TimeSpan timeout) bei System.ServiceModel.Channels.FramingDuplexSessionChannel.Receive(TimeSpan timeout) bei System.ServiceModel.Channels.FramingDuplexSessionChannel.TryReceive(TimeS pan timeout, Message& message) bei System.ServiceModel.Dispatcher.DuplexChannelBinder .Request(Message message, TimeSpan timeout) bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean o neway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) bei System.ServiceModel。 Channels.ServiceChannelProxy。InvokeService(IMethodCallMessage 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& msgData, Int32 type) bei WcfSys。 Shared.IService.AccessManager(List`1 status, String process, String dtFrom, String dtTo) bei WcfSys.Server.Program.Main() in WcfSys.Server\Program.cs:Zeile 66。

4

1 回答 1

0

实际上,您发送回客户端的是 a List<JobManager>,但实际上它是派生类。所以有两种方法可以解决这个问题:

  1. 将所有条目从复制JobBuilder到一个新List<JobManager>列表并返回该新列表
  2. 也做JobBuilder一个DataContract

由于 - 根据 OOP 原则 - 知道您返回的对象是 a JobBuilder,运行时会尝试序列化JobBuilder实例。但是,这不是 WCF 通信的已知类型。

于 2013-03-27T10:44:01.770 回答