这是我的课程:
[DataContract]
public class UserRepo
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Surname { get; set; }
[DataMember]
public bool IsActive { get; set; }
[DataMember]
public string Picture { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public int RoleId { get; set; }
[DataMember]
public string Email { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public int LoginCount { get; set; }
[DataMember]
public string RoleName { get; set; }
}
这是我的wcf函数:
public ReponseResult UpdateUser(UserRepo _userRepo)
{
try
{
var userDb = UserDB.GetInstance();
var result = userDb.UpdateUser(_userRepo);
var respReponseResult = new ReponseResult();
respReponseResult.Message = "Success";
JavaScriptSerializer js = new JavaScriptSerializer();
var returnObject = new ReturnObject()
{
ObjectName = "User Update",
Result = new List<object>() { result, false }
};
string json = js.Serialize(returnObject);
respReponseResult.Result = json;
return respReponseResult;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
将UserRepo对象的整数和布尔属性设置为0,然后将其发送给wcf后为false。我的错误在哪里?
答案 0 :(得分:0)
在调用WCF函数之前,要在哪里初始化UserRepo类?您是否正在使用UpdateUser方法检查单个值?
答案 1 :(得分:0)
我在项目中看到了这种情况。实际上,当代理从WSDL生成代码时,每个参数都会有一个自动生成的标志参数,例如如果您的字段是IsActive
,则自动生成的属性将是IsActiveSpecified
,请参见下文。
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public System.bool IsActive{
get {
return this.isActiveField;
}
set {
this.isActiveField= value;
this.RaisePropertyChanged("IsActive");
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IsActiveSpecified{
get {
return this.IsActiveSpecified;
}
set {
this.IsActiveSpecified= value;
this.RaisePropertyChanged("IsActiveSpecified");
}
}
因此,您应该设置IsActiveSpecified=true
,否则请设置为默认值。
希望能解决您的问题