嗨,我正在创建汽车租赁网络服务,但我需要将每个任务彼此分开。因此,我为客户提供了一项服务,它只是通用的名字、姓氏、年龄等。我还提供了一项雇用日期服务,其中包含雇用日期和雇用天数(稍后将用于计算成本)。
我的问题是试图链接 IHireDates
到ICustomers
下面的(最终是汽车)是一个设置示例,我只是使用控制台应用程序来托管这些不同的服务来练习。
下面是我的 ICustomers 和 IHireDate 服务我正在尝试将 IHireDate 链接到客户,但我不知道该怎么做:
ICustomer(服务器端)
namespace WcfServiceLibrary3
{
#region Customer DataContract
[DataContract(Name = "Customers")]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[Serializable]
public class Customers : ICustomers
{
[DataMember(Name = "CustomerID")]
public string CustomerID { get; set; }
[DataMember(Name = "FirstName")]
public string FirstName { get; set; }
[DataMember(Name = "LastName")]
public string LastName { get; set; }
[DataMember(Name = "Age")]
public string Age { get; set; }
IHireDates(服务器端):
namespace WcfServiceLibrary3
{
#region HireDate DataContract
[DataContract(Name = "HireDate")]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[Serializable]
public class HireDate : IHireDate
{
[DataMember(Name = "HireFromDate")]
public string HireFromDate { get; set; }
[DataMember(Name = "HireToDate")]
public string HireToDate { get; set; }
[DataMember(Name = "NumberOfDaysToHire")]
public string NumberOfDaysToHire { get; set; }
#endregion
#region Lists
List<HireDate> HireDates = new List<HireDate>();
#endregion
public void ICustomers.AddCustomerHireDates(string hirefromdate, string hiretodate, string customerID, string firstname, string lastname)
{
// not sure this will work
var result = ICustomers.Where(n => String.Equals(n.CustomerID, customerID)).FirstOrDefault();
if (result != null)
{
result.HireDates.Add(new ICustomers() { CustomerID = customerID, FirstName = firstname, LastName = lastname });
}
}
例如,我不确定这是否正确ICustomers.AddCustomerHireDates
,并ICustomers.Where
说客户没有定义在哪里。如果有人可以提供帮助,我真的不知道如何执行此跨 LINQ 服务,我将不胜感激。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.ServiceModel;
namespace WcfServiceLibrary3
{
#region Customer DataContract
[DataContract(Name = "Customers")]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[Serializable]
public class Customers : ICustomers
{
[DataMember(Name = "CustomerID")]
public string CustomerID { get; set; }
[DataMember(Name = "FirstName")]
public string FirstName { get; set; }
[DataMember(Name = "LastName")]
public string LastName { get; set; }
[DataMember(Name = "Age")]
public string Age { get; set; }
#endregion
#region Lists
List<Customers> customermembers = new List<Customers>();
int eCount = 0;
#endregion
public void AddCustomer(Customers customer)
{
customer.CustomerID = (++eCount).ToString();
customermembers.Add(customer);
//BinaryFormatter f = new BinaryFormatter();
//Stream w = new FileStream("c:\\list.dat", FileMode.Append);
//f.Serialize(w, staff);
//w.Close();
}
public void RemoveCustomer(string customerID)
{
customermembers.RemoveAll(s => s.CustomerID == customerID);
}
public List<Customers> GetCustomerCollection()
{
return customermembers;
}
public void UpdateCustomer(string customerID, Customers customer)
{
var findCustomerMember = customermembers.Where(s => s.CustomerID == customerID).FirstOrDefault();
if (findCustomerMember != null)
{
findCustomerMember.CustomerID = customer.CustomerID;
findCustomerMember.FirstName = customer.FirstName;
findCustomerMember.LastName = customer.LastName;
//findStaffMember.TimeAdded = staff.TimeAdded;
//BinaryFormatter f = new BinaryFormatter();
//Stream w = new FileStream("c:\\updatelist.dat", FileMode.Append);
//f.Serialize(w, staff);
//w.Close();
}
}
public List<Customers> GetCustomer(string anything)
{
List<Customers> customers = customermembers.Where(n =>
string.Equals(n.CustomerID, anything, StringComparison.CurrentCultureIgnoreCase)
|| string.Equals(n.FirstName, anything, StringComparison.CurrentCultureIgnoreCase)
|| string.Equals(n.LastName, anything, StringComparison.CurrentCultureIgnoreCase)
|| string.Equals(n.Age, anything, StringComparison.CurrentCultureIgnoreCase)
).ToList();
return customers;
}
}
}