无法通过WCF DataMembers

时间:2014-08-18 13:59:06

标签: c# wcf

问题:WCF datacontract类中的一些但不是所有数据名称都无法正常传递。

[ServiceContract]
public interface ICheckList
{
    [OperationContract]
    int UpsertManager(ManagerEntity newObj);
}

[DataContract]
[Serializable]
public class ManagerEntity
{
    [DataMember] public bool TrainingComplete{get;set;}
    [DataMember] public int IsPosted{get;set;}
    [DataMember] public DateTime TrainingDate{get;set;}
    [DataMember] public string Comments{get;set;}
}

客户端代码:

BRTWSLChecklist.ManagerEntity newModel = new BRTWSLChecklist.ManagerEntity();
newModel.TrainingComplete = model.HasTrainingDate;
newModel.Comments = model.Comments;
newModel.IsPosted = 1;
newModel.TrainingDate = DateTime.Today;

ChecklistClient.UpsertManager(newModel);

WCF方面:

public int UpsertManager(ManagerEntity newObj)
{
    bool t = newObj.TrainingComplete;   //always false
    DateTime x = newObj.TrainingDate;   //always equal to 1/1/0001
    string c = newObj.Comments;         //no problems here 
    int d = newObj.IsPosted;            //no problems here
}

任何想法为什么四分之二都没问题,但是布尔和日期时间都失败了?

1 个答案:

答案 0 :(得分:1)

您的客户端代码是否具有属性TrainingCompleteSpecifiedTrainingDateSpecified

如果是这样的话:当你为这些属性指定了一些值时,你必须将它们设置为真......

对于某些类型的属性,WCF无法区分您未指定任何值,或者您指定的值也看起来像“无”。因此,对于这些类型的属性,WCF客户端运行时将bool (property)Specified属性添加到客户端代码中;如果要将值传递给服务器,则必须将这些(property)Specified属性设置为true - 否则,您的值集将被忽略/在服务器端看不到

相关问题