C# 如何在使用Web API服务时为请求XML体生成正确的DTO类
我正在使用RestSharp和C#代码为只支持XML格式的WEB API服务操作放置数据对象(my#u对象) 我的问题: 如何创建正确的DTO类(如Analytics,请参见下文),以便在调用RestSharp的request.AddBody(my_object)方法时,RestSharp能够将数据块时间戳与Analytics DTO类的其他属性一起转换为XML属性 方法调用请求中的my_对象。AddBody(my_对象)是自定义分析SLOGS DTO类(请参见下文) 以下是Web API服务操作所需的请求Xml正文的示例:C# 如何在使用Web API服务时为请求XML体生成正确的DTO类,c#,asp.net-web-api,poco,restsharp,C#,Asp.net Web Api,Poco,Restsharp,我正在使用RestSharp和C#代码为只支持XML格式的WEB API服务操作放置数据对象(my#u对象) 我的问题: 如何创建正确的DTO类(如Analytics,请参见下文),以便在调用RestSharp的request.AddBody(my_object)方法时,RestSharp能够将数据块时间戳与Analytics DTO类的其他属性一起转换为XML属性 方法调用请求中的my_对象。AddBody(my_对象)是自定义分析SLOGS DTO类(请参见下文) 以下是Web API服务操
<AnalyticsLogs>
<Analytics Timestamp="1999-05-31T11:20:00">
<UserExpId>9223372036854775807</UserExpId>
<UserExpStatus>String content</UserExpStatus>
<Category>String content</Category>
<Value>2147483647</Value>
</Analytics>
<Analytics Timestamp="2007-05-12T11:20:00">
<UserExpId>8223372036854775899</UserExpId>
<UserExpStatus>String content</UserExpStatus>
<Category>String content</Category>
<Value>2147483647</Value>
</Analytics>
</AnalyticsLogs>
谢谢。
对于RestSharp,您使用属性序列化为属性
。这是
您不使用DateTime类型吗?您可以使用[XmlAttribute]作为时间戳属性。谢谢您的回复。我用RestSharp(隐式序列化的XML wih method request.AddBody(my_对象))尝试了这一点,但是当我调试该方法时,我没有看到“Timestamp”字段被序列化为XML属性:9/8/2014 5:12:27 PM 0类别测试操作测试2147483647 RestSharp.Parameter
public class Analytics
{
public long UserExpId { get;set;}
public string UserExpStatus { get; set;}
public string Category { get;set;}
public int Value {get; set;}
// how can I do for XML attribute Timestamp ??? It seems it can not a class property but I am not sure.
???
}
public class Analytics
{
public long UserExpId { get;set;}
public string UserExpStatus { get; set;}
public string Category { get;set;}
public int Value {get; set;}
[XmlAttribute]
public DateTime Timestamp { get; set; }
}
public class Analytics
{
public long UserExpId { get;set;}
public string UserExpStatus { get; set;}
public string Category { get;set;}
public int Value {get; set;}
[SerializeAsAttribute]
public DateTime Timestamp { get; set; }
}