我有一个与 ip 设备通信的 WCF SOAP Web 服务,每个设备都会给我一条消息,其中包括它们将要使用的每个变量的类型:
<tns1:Device wstop:topic="true">
<tnsavg:Logs wstop:topic="true">
<tt:MessageDescription IsProperty="true">
<tt:Data>
<tt:SimpleItemDescription Name="BaseId" Type="xsd:integer"/>
<tt:SimpleItemDescription Name="BootCount" Type="xsd:integer"/>
<tt:SimpleItemDescription Name="SystemLogId" Type="xsd:integer"/>
<tt:SimpleItemDescription Name="AccessLogId" Type="xsd:integer"/>
我可能会得到大约 20 到 30 个不同的项目,它们主要使用 int、boolean 和 string 类型。这是我可以收到的消息的示例:
<wsnt:Message>
<tt:Message UtcTime="2011-01-01T00:02:14.946Z">
<tt:Source/>
<tt:Data>
<tt:SimpleItem Name="BaseId" Value="3332536653"/>
<tt:SimpleItem Name="BootCount" Value="2525"/>
<tt:SimpleItem Name="SystemLogId" Value="73"/>
<tt:SimpleItem Name="AccessLogId" Value="9"/>
</tt:Data>
</tt:Message>
</wsnt:Message>
这里的主要问题是我想在控制器的属性中显示此消息,但我不知道显示它们的方式,以便将使用控制器的人可以使用它们以简单的方式获取信息。我曾想过创建一个以这种方式显示项目的类:
public class DataClass
{
public string Name;
public string Value;
public string Type;
}
我想到的其他选项是使用 ExpandoObjects,但这意味着用户必须对每个选项进行硬编码,并且控制器处理的每个设备可能有 40 条不同的消息。
有没有更好的方法来做到这一点,以便控制器用户可以轻松地实现它?