C#WCF服务器检索';列表<;T>';有1个条目,但客户端没有';我没有收到

C#WCF服务器检索';列表<;T>';有1个条目,但客户端没有';我没有收到,c#,fluent-nhibernate,wcf,endpoints,C#,Fluent Nhibernate,Wcf,Endpoints,我正在尝试从服务器(使用fluentNHibernate的服务器)检索客户端列表。 客户端对象如下所示: [DataContract] //[KnownType(typeof(System.Collections.Generic.List<ContactPerson>))] //[KnownType(typeof(System.Collections.Generic.List<Address>))] //[KnownType(typeof(System.Collectio

我正在尝试从服务器(使用fluentNHibernate的服务器)检索客户端列表。 客户端对象如下所示:

[DataContract]
//[KnownType(typeof(System.Collections.Generic.List<ContactPerson>))]
//[KnownType(typeof(System.Collections.Generic.List<Address>))]
//[KnownType(typeof(System.Collections.Generic.List<BatchRequest>))]
//[KnownType(typeof(System.Collections.Generic.List<Discount>))]
[KnownType(typeof(EClientType))]
[KnownType(typeof(EComType))]
public class Client
{
    #region Properties

[DataMember]
public virtual int ClientID { get; set; }

[DataMember]
public virtual EClientType ClientType { get; set; }

[DataMember]
public virtual string RegisterID {get; set;}

[DataMember]
public virtual string HerdCode { get; set; }

[DataMember]
public virtual string CompanyName { get; set; }

[DataMember]
public virtual bool InvoicePerBatch { get; set; }

[DataMember]
public virtual EComType ResultsComType { get; set; }

[DataMember]
public virtual EComType InvoiceComType { get; set; }



//[DataMember]
//public virtual IList<ContactPerson> Contacts { get; set; }

//[DataMember]
//public virtual IList<Address> Addresses { get; set; }

//[DataMember]
//public virtual IList<BatchRequest> Batches { get; set; }

//[DataMember]
//public virtual IList<Discount> Discounts { get; set; }

#endregion

#region Overrides

public override bool Equals(object obj)
{
    var other = obj as Client;
    if (other == null)
        return false;
    return other.GetHashCode() == this.GetHashCode();
}

public override int GetHashCode()
{
    return ClientID.GetHashCode() | ClientType.GetHashCode() | RegisterID.GetHashCode() |
            HerdCode.GetHashCode() | CompanyName.GetHashCode() | InvoicePerBatch.GetHashCode() |
            ResultsComType.GetHashCode() | InvoiceComType.GetHashCode();// | Contacts.GetHashCode() |
            //Addresses.GetHashCode() | Batches.GetHashCode() | Discounts.GetHashCode();
}

#endregion
}
[DataContract]
//[KnownType(typeof(System.Collections.Generic.List))]
//[KnownType(typeof(System.Collections.Generic.List))]
//[KnownType(typeof(System.Collections.Generic.List))]
//[KnownType(typeof(System.Collections.Generic.List))]
[KnownType(typeof(EClientType))]
[KnownType(typeof(EComType))]
公共类客户端
{
#区域属性
[数据成员]
公共虚拟int ClientID{get;set;}
[数据成员]
公共虚拟EClientType客户端类型{get;set;}
[数据成员]
公共虚拟字符串注册表ID{get;set;}
[数据成员]
公共虚拟字符串HerdCode{get;set;}
[数据成员]
公共虚拟字符串CompanyName{get;set;}
[数据成员]
公共虚拟bool InvoicePerBatch{get;set;}
[数据成员]
公共虚拟EComType ResultsComType{get;set;}
[数据成员]
公共虚拟EComType InvoiceComType{get;set;}
//[数据成员]
//公共虚拟IList联系人{get;set;}
//[数据成员]
//公共虚拟IList地址{get;set;}
//[数据成员]
//公共虚拟IList批处理{get;set;}
//[数据成员]
//公共虚拟IList折扣{get;set;}
#端区
#区域覆盖
公共覆盖布尔等于(对象对象对象)
{
var其他=作为客户的obj;
如果(其他==null)
返回false;
返回other.GetHashCode()==this.GetHashCode();
}
公共覆盖int GetHashCode()
{
返回ClientID.GetHashCode()| ClientType.GetHashCode()| RegisterID.GetHashCode()|
HerdCode.GetHashCode()| CompanyName.GetHashCode()| InvoicePerBatch.GetHashCode()|
结果ComType.GetHashCode()| InvoiceComType.GetHashCode();/| Contacts.GetHashCode()|
//Addresses.GetHashCode()| Batches.GetHashCode()|折扣.GetHashCode();
}
#端区
}
我已经尝试删除子列表,尽管即使使用这个简化版本的客户端,我仍然会遇到问题

我的fluent映射是:

public class ClientMap : ClassMap<Client>
    {
        public ClientMap()
        {
            Table("Clients");
            Id(p => p.ClientID);

            Map(p => p.ClientType).CustomType<EClientType>(); ;
            Map(p => p.RegisterID);
            Map(p => p.HerdCode);
            Map(p => p.CompanyName);
            Map(p => p.InvoicePerBatch);
            Map(p => p.ResultsComType).CustomType<EComType>();
            Map(p => p.InvoiceComType).CustomType<EComType>();

            //HasMany<ContactPerson>(p => p.Contacts)
            //    .KeyColumns.Add("ContactPersonID")
            //    .Inverse()
            //    .Cascade.All();

            //HasMany<Address>(p => p.Addresses)
            //    .KeyColumns.Add("AddressID")
            //    .Inverse()
            //    .Cascade.All();

            //HasMany<BatchRequest>(p => p.Batches)
            //    .KeyColumns.Add("BatchID")
            //    .Inverse()
            //    .Cascade.All();

            //HasMany<Discount>(p => p.Discounts)
            //    .KeyColumns.Add("DiscountID")
            //    .Inverse()
            //    .Cascade.All();

        } 
公共类ClientMap:ClassMap
{
公共客户端映射()
{
表(“客户”);
Id(p=>p.ClientID);
映射(p=>p.ClientType).CustomType();
Map(p=>p.RegisterID);
Map(p=>p.HerdCode);
Map(p=>p.CompanyName);
Map(p=>p.InvoicePerBatch);
Map(p=>p.ResultsComType).CustomType();
映射(p=>p.InvoiceComType).CustomType();
//有许多(p=>p.Contacts)
//.KeyColumns.Add(“ContactPersonID”)
//.Inverse()
//.Cascade.All();
//HasMany(p=>p.address)
//.KeyColumns.Add(“AddressID”)
//.Inverse()
//.Cascade.All();
//HasMany(p=>p.Batches)
//.KeyColumns.Add(“BatchID”)
//.Inverse()
//.Cascade.All();
//有很多(p=>p.折扣)
//.KeyColumns.Add(“折扣”)
//.Inverse()
//.Cascade.All();
} 
如下所示,客户端方法连接到服务器。服务器检索列表,对象中的所有内容看起来都是正确的,但是,当它返回时,客户端没有接收任何内容(它接收一个列表对象,但其中没有任何内容)

调用方法如下:

public List<s.Client> GetClientList()
        {
            try
            {
                s.DataServiceClient svcClient = new s.DataServiceClient();
                svcClient.Open();

                List<s.Client> clients = new List<s.Client>();

                clients = svcClient.GetClientList().ToList<s.Client>();

                svcClient.Close(); //when receiving focus from server, the clients object has a count of 0

                return clients;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return null;
        }
public List GetClientList()
{
尝试
{
s、 DataServiceClient svcClient=新的s.DataServiceClient();
svcClient.Open();
列表客户端=新列表();
clients=svcClient.GetClientList().ToList();
svcClient.Close();//从服务器接收焦点时,clients对象的计数为0
返回客户;
}
捕获(例外e)
{
MessageBox.Show(e.Message);
}
返回null;
}
和服务器方法:

public IList<Client> GetClientList()
        {
            var clients = new List<Client>();

            try
            {
                using (var session = SessionHelper.OpenSession())
                {
                    clients = session.Linq<Client>().Where(p => p.ClientID > 0).ToList<Client>();
                }
            }
            catch (Exception e)
            {
                EventLog.WriteEntry("eCOWS.Data", e.Message);
            }

            return clients; //returns a list with 1 client in it
        }
public Client[] GetClientList()
{
    try
    {
        using (var session = SessionHelper.OpenSession())
        {
            return session.Linq<Client>().Where(p => p.ClientID > 0).ToArray<Client>();
        }
    }
    catch (Exception e)
    {
        EventLog.WriteEntry("eCOWS.Data", e.Message);
        return null;
    }
}
public IList GetClientList()
{
var clients=newlist();
尝试
{
使用(var session=SessionHelper.OpenSession())
{
clients=session.Linq().Where(p=>p.ClientID>0.ToList();
}
}
捕获(例外e)
{
EventLog.WriteEntry(“eCOWS.Data”,e.Message);
}
return clients;//返回包含1个客户机的列表
}
服务器方法接口是:

 [UseNetDataContractSerializer]
        [OperationContract]
        IList<Client> GetClientList();
[UseNetDataContractSerializer]
[经营合同]
IList GetClientList();
作为最终参考,以下是我的客户端app.config条目:

 <system.serviceModel>

        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IDataService" listenBacklog="10" maxConnections="10"
                         transferMode="Buffered" transactionProtocol="OleTransactions"
                         maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" 
                         receiveTimeout="00:10:00" sendTimeout="00:10:00">
                      <readerQuotas maxDepth="51200000" maxStringContentLength="51200000" 
                                    maxArrayLength="51200000" maxBytesPerRead="51200000" 
                                    maxNameTableCharCount="51200000" />
                  <security mode="Transport"/>
                </binding>
            </netTcpBinding>
        </bindings>

        <client>
            <endpoint address="net.tcp://localhost:9000/eCOWS/DataService"
                binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IDataService"
                contract="eCowsDataService.IDataService" name="NetTcpBinding_IDataService"
                behaviorConfiguration="eCowsEndpointBehavior">
            </endpoint>

           <endpoint address="MEX"
                     binding="mexHttpBinding"
                     contract="IMetadataExchange" />

        </client>

        <behaviors>
          <endpointBehaviors>
            <behavior name="eCowsEndpointBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </endpointBehaviors>
        </behaviors>

    </system.serviceModel>

和我的服务器app.config:

    <system.serviceModel>

      <bindings>
        <netTcpBinding>
          <binding name="netTcpBinding"
                   maxConnections="10" listenBacklog="10"
                   transferMode="Buffered" transactionProtocol="OleTransactions" 
                   maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
                   sendTimeout="00:10:00" receiveTimeout="00:10:00">
            <readerQuotas maxDepth="51200000" maxStringContentLength="51200000" 
                          maxArrayLength="51200000" maxBytesPerRead="51200000" 
                          maxNameTableCharCount="51200000" />
            <security mode="Transport"/>
          </binding>
        </netTcpBinding>
      </bindings>

      <services>
      <service name="eCows.Data.Services.DataService" behaviorConfiguration="eCowsServiceBehavior">

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9001/eCOWS/" />
            <add baseAddress="net.tcp://localhost:9000/eCOWS/" />
          </baseAddresses>
        </host>

        <endpoint address="DataService" 
                  binding="netTcpBinding" 
                  contract="eCows.Data.Services.IDataService"
                  behaviorConfiguration="eCowsEndpointBehaviour">
        </endpoint>

        <endpoint address="MEX"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="eCowsEndpointBehaviour">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>      
      <serviceBehaviors>
        <behavior name="eCowsServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceThrottling maxConcurrentCalls="10" maxConcurrentSessions="10"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
        <behavior name="MexBehaviour">
          <serviceMetadata />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

我过去经常遇到“套接字关闭/网络或超时”错误,跟踪清楚地显示,在回调上它正在寻找侦听端点,但找不到。无论如何,在添加UseNetSerializer后,错误消失了,但现在我什么也没有得到

另外,如果我添加了所有注释掉的列表项,我仍然从数据库中检索一个条目,但仍然没有在客户端接收到任何内容

如果我删除[UseNetDataContractSerializer],我会得到