我有以下對象,當我指定像int,string這樣的標準對象而不是自定義對象時,它工作正常。WCF中的自定義對象
[DataContract(Namespace = "")]
public class StatusLog<TItem>
{
/// <summary>
/// Gets or sets the key.
/// </summary>
/// <value>
/// The key.
/// </value>
[DataMember]
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the action status.
/// </summary>
/// <value>
/// The action status.
/// </value>
[DataMember]
public ActionStatus ActionStatus { get; set; }
/// <summary>
/// Gets or sets the object.
/// </summary>
/// <value>
/// The object.
/// </value>
[DataMember]
public TItem Object { get; set; }
/// <summary>
/// Gets or sets the message.
/// </summary>
/// <value>
/// The message.
/// </value>
[DataMember]
public string Message { get; set; }
}
這工作: 返回新StatusLog {ID = Guid.NewGuid(),ActionStatus = ActionStatus.Deleted,對象= Convert.ToInt32(ID),消息= 「節點成功刪除」};
這是行不通的: new StatusLog {Id = Guid.NewGuid(),ActionStatus = ActionStatus.Created,Object = MyCustomObject};
MyCustomObject的類型是否也用序列化屬性標記('[DataContract]','[DataMember]')? –
是的。他們都是。 –