我使用 SVCUTIL 从 XSD 生成一个类。我很难弄清楚如何获取传入的请求对象并从对象中检索“MsgType”值。
我想通过这样做,我可以简单地使用以下方法访问数据:
request.Request.MsgType
然而,事情并没有这么简单。'request' 给我的唯一选项是: Equals GetHashCode GetSchema GetType Nodes ReadXML ToString WriteXML
为了访问 MsgType,我需要对序列化对象进行某种类型的转换吗?
public ServiceProviderTic callRequestFunc(ServiceProviderTic request) {
//How do I get request.Request.MsgType Value?
}
生成类中的根元素:
using System.Runtime.Serialization;
[assembly: System.Runtime.Serialization.ContractNamespaceAttribute("", ClrNamespace="")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="RequestType", Namespace="")]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(ResponseType))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DateTimeInfoType))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(OriginType))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(LocaleInfoType))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(ProductType))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(ValueType))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(AuthInfoType))]
public partial class RequestType : object, System.Runtime.Serialization.IExtensibleDataObject
{
private RequestType.MsgTypeType MsgTypeField;
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public RequestType.MsgTypeType MsgType
{
get
{
return this.MsgTypeField;
}
set
{
this.MsgTypeField = value;
}
}
[System.Runtime.Serialization.DataContractAttribute(Name="RequestType.MsgTypeType", Namespace="")]
public enum MsgTypeType : int
{
[System.Runtime.Serialization.EnumMemberAttribute()]
act = 0
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Xml.Serialization.XmlSchemaProviderAttribute("ExportSchema")]
[System.Xml.Serialization.XmlRootAttribute(IsNullable=false)]
public partial class ServiceProviderTic : object, System.Xml.Serialization.IXmlSerializable
{
private System.Xml.XmlNode[] nodesField;
private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("ServiceProviderTic", "");
public System.Xml.XmlNode[] Nodes
{
get
{
return this.nodesField;
}
set
{
this.nodesField = value;
}
}
public void ReadXml(System.Xml.XmlReader reader)
{
this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader);
}
public void WriteXml(System.Xml.XmlWriter writer)
{
System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes);
}
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas)
{
System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName);
return typeName;
}
XML:
<ServiceProviderTic>
<Request>
<MsgType>act</MsgType>
XSD 架构
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ServiceProvideTic" nillable="false">
<xs:annotation>
<xs:documentation></xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Version" type="xs:string" nillable="false"/>
<xs:choice>
<xs:element name="Request" type="RequestType" nillable="false"/>
<xs:element name="Response" type="ResponseType" nillable="false"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="RequestType">
<xs:annotation>
<xs:documentation> Request Information</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="MsgType" nillable="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="act"/>