Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF错误“;序列不包含任何元素";-&引用;集合超出了固定大小”;_C#_Wcf_Windows Services_Nettcpbinding - Fatal编程技术网

C# WCF错误“;序列不包含任何元素";-&引用;集合超出了固定大小”;

C# WCF错误“;序列不包含任何元素";-&引用;集合超出了固定大小”;,c#,wcf,windows-services,nettcpbinding,C#,Wcf,Windows Services,Nettcpbinding,我是WCF的新手。我开始创建一个WCF项目,将人们的信息保存在EF数据库中 我有很多错误,并通过在不同的网站上搜索来修复它们,但最近我被一些错误阻止,无法修复它们 我的项目是带有实体框架的n层数据模型。服务器有4层 DAL(包含EF数据模型)-->BLL(用于插入/更新/删除功能的类库)-->服务层(wcf类库)-->主机层(windows服务) 我在Windows服务中托管我的服务。服务绑定是nettcpbinding。我将服务配置为true,因此这里没有问题 我有一个名为“Common”(类

我是WCF的新手。我开始创建一个WCF项目,将人们的信息保存在EF数据库中

我有很多错误,并通过在不同的网站上搜索来修复它们,但最近我被一些错误阻止,无法修复它们

我的项目是带有实体框架的n层数据模型。服务器有4层

DAL(包含EF数据模型)-->BLL(用于插入/更新/删除功能的类库)-->服务层(wcf类库)-->主机层(windows服务)

我在Windows服务中托管我的服务。服务绑定是nettcpbinding。我将服务配置为true,因此这里没有问题

我有一个名为“Common”(类库)的项目,所有4个项目都可以访问它,如您所知,我创建了一个代码生成器,并将生成的类粘贴到Common(用DAL分隔类模型)

现在cient只有(主机层)服务引用。在客户端,我有服务类中的所有实体类

当我想将对象插入数据库时,问题就出现了。见下面的代码:

服务器端(位于BLL和服务层):

namespace BLL
{
    public static class bz
    {
        public static class People
        {
            public static void myInsert(Common.People p, out bool Result)
            {
                Result = false;

                Common.EFContainer cntx = new Common.EFContainer();
                cntx.ContextOptions.ProxyCreationEnabled = false;
                cntx.ContextOptions.LazyLoadingEnabled = false;

                if (p.FirstName == "" || p.FirstName == null)
                {
                   throw new Exception("Fill Fist Name") ;
                }
                //  ... more validate
                //-->I Do not use first or single etc in validating<--
                try
                {

                    cntx.Peoples.AddObject(p);
                    cntx.SaveChanges();
                    Result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        public static class Gender
        {
             public static List<Common.Gender> GetData()
             {
                Common.EFContainer cntx = new Common.EFContainer();
                cntx.ContextOptions.ProxyCreationEnabled = false;
                cntx.ContextOptions.LazyLoadingEnabled = false;

                return cntx.Genders.ToList();
             }
        }
    }
}

namespace ServiceLayer
{

[ServiceContract(SessionMode = SessionMode.Required)]
public interface IService
{
    [FaultContract(typeof(NormalExeption))]
    [OperationContract]
    bool AddToPeople(Common.People p);

    [OperationContract]
    List<Common.Gender> GetGenders();
}

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode =     System.ServiceModel.ConcurrencyMode.Single)]
 public class myService : IService
 {
    [OperationBehavior]
    public bool AddToPeople(Common.People p)
    {
      try
        {
            BLL.bz.People.myInsert(p, out result);

             return result;
        }
        catch (Exception ex)
        { 
           var exep = new NormalExeption(ex.Message, ex.Source, 0, Icons.Error);
           throw new FaultException<NormalExeption>(exep, new FaultReason(new FaultReasonText(ex.Message)));
        }
    }
    [OperationBehavior]
    public  List<Common.Gender> GetGenders()
    {
       return BLL.bz.Gender.GetData();
    }
 }
ServiceRef.People p = new ServiceRef.People();
ServiceRef.myServiceClient client=new ServiceRef.myServiceClient();

p.FirstName="S";

//... Fill Other Fields 

p.Childs=new List<ServiceRef.Child>();
p.Childs.Add(new ServiceRef.Child(){FirstName="A"});

p.Gender=client.GetGenders.first();

//... --->No Error Happen Till Here Error Is After This in Service<---


try
{
  client.AddToPeople(p);
}
Catch(FaultException fe)
{
  messagebox.show(fe.Detail.Message);
}
名称空间BLL
{
公共静态类bz
{
公共阶层人士
{
公共静态无效myInsert(Common.p,out bool结果)
{
结果=假;
Common.EFContainer cntx=新的Common.EFContainer();
cntx.ContextOptions.ProxyCreationEnabled=false;
cntx.ContextOptions.LazyLoadingEnabled=false;
if(p.FirstName==“”| | p.FirstName==null)
{
抛出新异常(“填入名字”);
}
//…更多验证
//-->我不使用first或single etc进行验证,直到服务中出现此错误之后才发生错误