1、创建WCF接口,创建普通的类库文件,不要创建WCF类库,不清楚原因的童鞋自己试一下,就知道两者的不同了,代码如下:
using System.Collections.Generic; using System.ServiceModel; using WCF.EF.Entity.DataContract; namespace WCF.ServiceInterface { [ServiceContract] public interface IGroupCustomers { [OperationContract] List<GroupCustomerInfoDCT> GetGroupCustomersList(); } }
2、创建实体,此项目使用的是Entity FrameWork6.1.2,网上有很多项目的步骤,在此不详细说明了,然后建立数据契约文件,数据契约的数据最终来源于数据库实体,所以将数据契约放在此:
using System; using System.Runtime.Serialization; namespace WCF.EF.Entity.DataContract { [DataContract] public class GroupCustomerInfoDCT { /// <summary> /// 团队名称 /// </summary> [DataMember] public string GroupName { get; set; } /// <summary> /// 分组号 /// </summary> /// <value>The grouping NO.</value> [DataMember] public int GroupingNO { set; get; } private string _ProductDept = string.Empty; [DataMember] public string ProductDept { get { return _ProductDept; } set { _ProductDept = value; } } private string _BirthDayDate = string.Empty; [DataMember] public string BirthDayDate { get { return _BirthDayDate; } set { _BirthDayDate = value; } } /// <summary> /// 客户ID /// </summary> private int _ID; /// <summary> /// 客户姓名 /// </summary> private string _Name = string.Empty; /// <summary> /// 客户性别 /// </summary> private System.Nullable<int> _Sex; /// <summary> /// 拼音姓 /// </summary> private string _FirstName = string.Empty; /// <summary> /// 拼音名 /// </summary> private string _LastName = string.Empty; /// <summary> /// 拼音姓名 /// </summary> private string _SpellName = string.Empty; [DataMember] public string SpellName { get { return _SpellName; } set { _SpellName = value; } } /// <summary> /// 用户名 /// </summary> private string _FullName = string.Empty; /// <summary> /// 生日 /// </summary> private System.Nullable<System.DateTime> _BirthDay; /// <summary> /// 手机 /// </summary> private string _Mobile = string.Empty; /// <summary> /// 邮件 /// </summary> private string _EMAIL = string.Empty; /// <summary> /// 办公电话 /// </summary> private string _OfficeTel = string.Empty; /// <summary> /// 家庭电话 /// </summary> private string _FamilyTel = string.Empty; /// <summary> /// 首选联系方式 /// </summary> private System.Nullable<int> _FirstContactMethod; /// <summary> /// VIP卡 /// </summary> private string _VipCardID = string.Empty; /// <summary> /// 地址 /// </summary> private string _Adress = string.Empty; /// <summary> /// 密码 /// </summary> private string _Password = string.Empty; /// <summary> /// 客人级别 /// </summary> private System.Nullable<int> _MemLevel; /// <summary> /// 前台资料是否完备 /// </summary> private System.Nullable<int> _FileIsOK; /// <summary> /// 审核状态 /// </summary> private System.Nullable<int> _ApprovalStatusID; /// <summary> /// 审核人 /// </summary> private System.Nullable<int> _ApprovalBy; /// <summary> /// 审核时间 /// </summary> private System.Nullable<System.DateTime> _ApprovalDate; /// <summary> /// 是否会员 /// </summary> private System.Nullable<int> _IsMember; /// <summary> /// 是否有效 /// </summary> private System.Nullable<int> _IsValid; /// <summary> /// 注册来源部门Id /// </summary> private System.Nullable<int> _RegistSource; /// <summary> /// 注册人员 /// </summary> private System.Nullable<int> _RegistBy; /// <summary> /// 注册时间 /// </summary> private System.Nullable<System.DateTime> _RegistDate; /// <summary> /// 最新更新时间 /// </summary> private System.Nullable<System.DateTime> _LastUpdate; /// <summary> /// 消费金额(非团) /// </summary> private System.Nullable<double> _ConsumeAmt; /// <summary> /// 消费次数(非团) /// </summary> private System.Nullable<int> _ConsumeTimes; /// <summary> /// 消费金额(团) /// </summary> private System.Nullable<double> _GroupConsumeAmt; /// <summary> /// 消费次数(团) /// </summary> private System.Nullable<int> _GroupConsumeTimes; /// <summary> /// 身份证号 /// </summary> private string _IDNo = string.Empty; /// <summary> /// 是否黑名单 /// </summary> private System.Nullable<int> _IsBlackPerson; /// <summary> /// 团队客人子表ID /// </summary> private int _Oci_Id; /// <summary> /// 大订单ID /// </summary> private System.Nullable<int> _Main_Order_Id; /// <summary> /// 子订单ID /// </summary> private System.Nullable<int> _Group_Order_Id; /// <summary> /// 团队ID /// </summary> private int _Group_Id; /// <summary> /// 客户ID /// </summary> private System.Nullable<int> _Customer_Id; /// <summary> /// 价格类型 /// </summary> private System.Nullable<int> _Price_Type; /// <summary> /// 保险金额 /// </summary> private System.Nullable<double> _Insurance; /// <summary> /// 旅游证据类型 /// </summary> private System.Nullable<int> _Passport_type_id; /// <summary> /// 旅游证件号 /// </summary> private string _Passport_id = string.Empty; /// <summary> /// 签发城市 /// </summary> private System.Nullable<int> _Issue_city; /// <summary> /// 签发机关 /// </summary> private string _Issue_unit = string.Empty; /// <summary> /// 签发日期 /// </summary> private string _Issue_date = string.Empty; /// <summary> /// 有效期 /// </summary> private string _Valid_date = string.Empty; /// <summary> /// 护照目的地国家 /// </summary> private System.Nullable<int> _Departure_card; /// <summary> /// 客人状态 /// </summary> private System.Nullable<int> _Status; /// <summary> /// 审核状态 /// </summary> private System.Nullable<int> _Auditing_Sign; /// <summary> /// 审核人 /// </summary> private System.Nullable<int> _Employee_Id; /// <summary> /// 审核时间 /// </summary> private System.Nullable<System.DateTime> _Auditing_Time; /// <summary> /// 审核信息 /// </summary> private string _Check_Info = string.Empty; /// <summary> /// 审核员工姓名 /// </summary> private string strEmployeeName = string.Empty; [DataMember] public string EmployeeName { get { return strEmployeeName; } set { strEmployeeName = value; } } /// <summary> /// 审核标志名称 /// </summary> private string strAuditingSignName = string.Empty; [DataMember] public string AuditingSignName { get { return strAuditingSignName; } set { strAuditingSignName = value; } } /// <summary> /// 分房要求 /// </summary> private System.Nullable<int> _Room_require; /// <summary> /// 分房要求中文 /// </summary> private string _Room_requireName = string.Empty; [DataMember] public string Room_requireName { get { return _Room_requireName; } set { _Room_requireName = value; } } /// <summary> /// 分房号 /// </summary> private string _Room_no = string.Empty; /// <summary> /// 特殊需求 /// </summary> private string _Special_require = string.Empty; /// <summary> /// 通知信息 /// </summary> private System.Nullable<int> _Inform_Flag; /// <summary> /// 销售人ID /// </summary> private int _Input_User; /// <summary> /// 销售部门ID /// </summary> private string _Input_Dept = string.Empty; /// <summary> /// 大订单No /// </summary> private string _Main_Order_NO = string.Empty; /// <summary> /// 订单分房号 /// </summary> private string _Order_Room_NO = string.Empty; [DataMember] public string Order_Room_NO { get { return _Order_Room_NO; } set { _Order_Room_NO = value; } } /// <summary> /// 团队编号 /// </summary> private string _Group_NO = string.Empty; [DataMember] public string Group_NO { get { return _Group_NO; } set { _Group_NO = value; } } /// <summary> /// 出生城市 /// </summary> private string _Birth_Location = string.Empty; [DataMember] public string Birth_Location { get { return _Birth_Location; } set { _Birth_Location = value; } } /// <summary> /// 子订单No /// </summary> private string _Sub_Order_NO = string.Empty; /// <summary> /// 性别文字 /// </summary> private string _SexName = string.Empty; /// <summary> /// 价格类型名字 /// </summary> private string _Price_TypeName = string.Empty; /// <summary> /// 首选联系方式名字 /// </summary> private string _FirstContactMethodName = string.Empty; /// <summary> /// 旅游证件名称 /// </summary> private string _Passport_type_Name = string.Empty; /// <summary> /// 签发城市名字 /// </summary> private string _Issue_cityName = string.Empty; /// <summary> /// 销售部门名字 /// </summary> private string _Input_DeptName = string.Empty; /// <summary> /// 销售人名字 /// </summary> private string _Input_UserName = string.Empty; /// <summary> /// 客人状态名字 /// </summary> private string _StatusName = string.Empty; /// <summary> /// 国内出境 /// </summary> private int _SubAttribute; /// <summary> /// 选择需要 /// </summary> private int intSelectUse; [DataMember] public int IntSelectUse { get { return intSelectUse; } set { intSelectUse = value; } } [DataMember] public int SubAttribute { get { return _SubAttribute; } set { _SubAttribute = value; } } [DataMember] public string StatusName { get { return _StatusName; } set { _StatusName = value; } } [DataMember] public string Input_DeptName { get { return _Input_DeptName; } set { _Input_DeptName = value; } } [DataMember] public string Input_UserName { get { return _Input_UserName; } set { _Input_UserName = value; } } [DataMember] public string Issue_cityName { get { return _Issue_cityName; } set { _Issue_cityName = value; } } [DataMember] public string Passport_type_Name { get { return _Passport_type_Name; } set { _Passport_type_Name = value; } } [DataMember] public string FirstContactMethodName { get { return _FirstContactMethodName; } set { _FirstContactMethodName = value; } } [DataMember] public string Price_TypeName { get { return _Price_TypeName; } set { _Price_TypeName = value; } } [DataMember] public string SexName { get { return _SexName; } set { _SexName = value; } } [DataMember] public int ID { get { return _ID; } set { _ID = value; } } [DataMember] public string Name { get { return _Name; } set { _Name = value; } } [DataMember] public System.Nullable<int> Sex { get { return _Sex; } set { _Sex = value; } } [DataMember] public string FirstName { get { return _FirstName; } set { _FirstName = value; } } [DataMember] public string LastName { get { return _LastName; } set { _LastName = value; } } [DataMember] public string FullName { get { return _FullName; } set { _FullName = value; } } [DataMember] public System.Nullable<System.DateTime> BirthDay { get { return _BirthDay; } set { _BirthDay = value; } } [DataMember] public string Mobile { get { return _Mobile; } set { _Mobile = value; } } [DataMember] public string EMAIL { get { return _EMAIL; } set { _EMAIL = value; } } [DataMember] public string OfficeTel { get { return _OfficeTel; } set { _OfficeTel = value; } } [DataMember] public string FamilyTel { get { return _FamilyTel; } set { _FamilyTel = value; } } [DataMember] public System.Nullable<int> FirstContactMethod { get { return _FirstContactMethod; } set { _FirstContactMethod = value; } } [DataMember] public string VipCardID { get { return _VipCardID; } set { _VipCardID = value; } } [DataMember] public string Adress { get { return _Adress; } set { _Adress = value; } } [DataMember] public string Password { get { return _Password; } set { _Password = value; } } [DataMember] public System.Nullable<int> MemLevel { get { return _MemLevel; } set { _MemLevel = value; } } [DataMember] public System.Nullable<int> FileIsOK { get { return _FileIsOK; } set { _FileIsOK = value; } } [DataMember] public System.Nullable<int> ApprovalStatusID { get { return _ApprovalStatusID; } set { _ApprovalStatusID = value; } } [DataMember] public System.Nullable<int> ApprovalBy { get { return _ApprovalBy; } set { _ApprovalBy = value; } } [DataMember] public System.Nullable<System.DateTime> ApprovalDate { get { return _ApprovalDate; } set { _ApprovalDate = value; } } [DataMember] public System.Nullable<int> IsMember { get { return _IsMember; } set { _IsMember = value; } } [DataMember] public System.Nullable<int> IsValid { get { return _IsValid; } set { _IsValid = value; } } [DataMember] public System.Nullable<int> RegistSource { get { return _RegistSource; } set { _RegistSource = value; } } [DataMember] public System.Nullable<int> RegistBy { get { return _RegistBy; } set { _RegistBy = value; } } [DataMember] public System.Nullable<System.DateTime> RegistDate { get { return _RegistDate; } set { _RegistDate = value; } } [DataMember] public System.Nullable<System.DateTime> LastUpdate { get { return _LastUpdate; } set { _LastUpdate = value; } } [DataMember] public System.Nullable<double> ConsumeAmt { get { return _ConsumeAmt; } set { _ConsumeAmt = value; } } [DataMember] public System.Nullable<int> ConsumeTimes { get { return _ConsumeTimes; } set { _ConsumeTimes = value; } } [DataMember] public System.Nullable<double> GroupConsumeAmt { get { return _GroupConsumeAmt; } set { _GroupConsumeAmt = value; } } [DataMember] public System.Nullable<int> GroupConsumeTimes { get { return _GroupConsumeTimes; } set { _GroupConsumeTimes = value; } } [DataMember] public string IDNo { get { return _IDNo; } set { _IDNo = value; } } [DataMember] public System.Nullable<int> IsBlackPerson { get { return _IsBlackPerson; } set { _IsBlackPerson = value; } } [DataMember] public int Oci_Id { get { return _Oci_Id; } set { _Oci_Id = value; } } [DataMember] public System.Nullable<int> Main_Order_Id { get { return _Main_Order_Id; } set { _Main_Order_Id = value; } } [DataMember] public System.Nullable<int> Group_Order_Id { get { return _Group_Order_Id; } set { _Group_Order_Id = value; } } [DataMember] public int Group_Id { get { return _Group_Id; } set { _Group_Id = value; } } [DataMember] public System.Nullable<int> Customer_Id { get { return _Customer_Id; } set { _Customer_Id = value; } } [DataMember] public System.Nullable<int> Price_Type { get { return _Price_Type; } set { _Price_Type = value; } } [DataMember] public System.Nullable<double> Insurance { get { return _Insurance; } set { _Insurance = value; } } [DataMember] public System.Nullable<int> Passport_type_id { get { return _Passport_type_id; } set { _Passport_type_id = value; } } [DataMember] public string Passport_id { get { return _Passport_id; } set { _Passport_id = value; } } [DataMember] public System.Nullable<int> Issue_city { get { return _Issue_city; } set { _Issue_city = value; } } [DataMember] public string Issue_unit { get { return _Issue_unit; } set { _Issue_unit = value; } } [DataMember] public string Issue_date { get { return _Issue_date; } set { _Issue_date = value; } } [DataMember] public string Valid_date { get { return _Valid_date; } set { _Valid_date = value; } } [DataMember] public System.Nullable<int> Departure_card { get { return _Departure_card; } set { _Departure_card = value; } } [DataMember] public System.Nullable<int> Status { get { return _Status; } set { _Status = value; } } [DataMember] public System.Nullable<int> Auditing_Sign { get { return _Auditing_Sign; } set { _Auditing_Sign = value; } } [DataMember] public System.Nullable<int> Employee_Id { get { return _Employee_Id; } set { _Employee_Id = value; } } [DataMember] public System.Nullable<System.DateTime> Auditing_Time { get { return _Auditing_Time; } set { _Auditing_Time = value; } } [DataMember] public string Check_Info { get { return _Check_Info; } set { _Check_Info = value; } } [DataMember] public System.Nullable<int> Room_require { get { return _Room_require; } set { _Room_require = value; } } [DataMember] public string Room_no { get { return _Room_no; } set { _Room_no = value; } } [DataMember] public string Special_require { get { return _Special_require; } set { _Special_require = value; } } [DataMember] public System.Nullable<int> Inform_Flag { get { return _Inform_Flag; } set { _Inform_Flag = value; } } [DataMember] public int Input_User { get { return _Input_User; } set { _Input_User = value; } } [DataMember] public string Input_Dept { get { return _Input_Dept; } set { _Input_Dept = value; } } [DataMember] public string Main_Order_NO { get { return _Main_Order_NO; } set { _Main_Order_NO = value; } } [DataMember] public string Sub_Order_NO { get { return _Sub_Order_NO; } set { _Sub_Order_NO = value; } } //OrderContactPerson-订单联系人 private string _OrderContactPerson = string.Empty; [DataMember] public string OrderContactPerson { get { return _OrderContactPerson; } set { _OrderContactPerson = value; } } //OrderContactInfo-订单联系方式 private string _OrderContactInfo = string.Empty; [DataMember] public string OrderContactInfo { get { return _OrderContactInfo; } set { _OrderContactInfo = value; } } //子订单备注 private string _SubOrderRemark = string.Empty; [DataMember] public string SubOrderRemark { get { return _SubOrderRemark; } set { _SubOrderRemark = value; } } /// <summary> /// 邮轮房型 /// </summary> [DataMember] public string CruiseTypeName { get; set; } /// <summary> /// 附加服务 /// </summary> [DataMember] public string AddServices { get; set; } /// <summary> /// 观光套餐服务 /// </summary> [DataMember] public string AddSortServices { get; set; } /// <summary> /// 是否是邮轮团队 /// </summary> [DataMember] public bool IsCruiseGroup { get; set; } /// <summary> /// 会员级别 /// </summary> [DataMember] public string MemLevelText { get; set; } /// <summary> /// 订单下单日期 /// </summary> [DataMember] public DateTime InputDate { get; set; } /// <summary> /// 联运政策城市 /// </summary> [DataMember] public string CityName { get; set; } } }
2、创建接口的实现类:
using System; using System.Collections.Generic; using System.Linq; using WCF.EF.Entity; using WCF.EF.Entity.DataContract; using WCF.ServiceInterface; namespace WCF.ServiceImpl { public class GroupCustomers:IGroupCustomers,IDisposable { public List<EF.Entity.DataContract.GroupCustomerInfoDCT> GetGroupCustomersList() { //可以得到最终执行的SQL语句 HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize(); using (CYTSERPEntities db = new CYTSERPEntities()) { var tmp = (from p in db.VW_Group_CUSTOMER_INFO where p.Main_Order_Id == 3814 //join m in db.CM_Member on p.Customer_Id equals m.ID into ms //from m in ms.DefaultIfEmpty() select new GroupCustomerInfoDCT { Group_Id =(int)p.Group_Id, Group_NO = (p.Grouping_NO).ToString() }).ToList(); return tmp; } } public void Dispose() { } } }
4、创建Host