我有以下 C# 类,但它不起作用。
[XmlRoot(ElementName = "品牌")] 公共课品牌 { [XmlAttribute(AttributeName = "类型", 命名空间 = "http://www.w3.org/2001/XMLSchema-instance")] 公共字符串类型{获取;放; } [Xml文本] 公共字符串文本{获取;放; } }
[XmlRoot(ElementName = "DatiPratica")]
[XmlType(TypeName = "ElementiDatiPratica", Namespace = "http://crogwebnew.satoprg.net/soap")]
public class DatiPratica
{
[XmlElement(ElementName = "Brand")]
public Brand Brand { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Type { get; set; }
[XmlAttribute(AttributeName = "soap", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soap { get; set; }
}
[XmlRoot(ElementName = "RichiestaFin", Namespace = "http://www.w3.org/2001/XMLSchema")]
public class RichiestaFin
{
[XmlElement(ElementName = "DatiPratica")]
public DatiPratica DatiPratica { get; set; }
[XmlAttribute(AttributeName = "encodingStyle", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public string EncodingStyle { get; set; }
}
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "RichiestaFin", Namespace = "http://www.w3.org/2001/XMLSchema")]
public RichiestaFin RichiestaFin { get; set; }
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Header", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public string Header { get; set; }
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName = "xsd", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsd { get; set; }
[XmlAttribute(AttributeName = "soapenv", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soapenv { get; set; }
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
public Envelope()
{
ns.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");
}
}
这是基于提供的 SOAP 请求结构(XmlRoot、XmlElement RichiestaFin 不是根)的类的更正版本。
using System.Xml.Serialization;
[XmlRoot(ElementName = "Brand", Namespace = "http://crogwebnew.satoprg.net/soap")]
public class Brand
{
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Type { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "DatiPratica", Namespace = "http://crogwebnew.satoprg.net/soap")]
public class DatiPratica
{
[XmlElement(ElementName = "Brand", Namespace = "http://crogwebnew.satoprg.net/soap")]
public Brand Brand { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Type { get; set; }
[XmlAttribute(AttributeName = "soap", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soap { get; set; }
}
[XmlRoot(ElementName = "RichiestaFin", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class RichiestaFin
{
[XmlElement(ElementName = "DatiPratica", Namespace = "http://crogwebnew.satoprg.net/soap")]
public DatiPratica DatiPratica { get; set; }
}
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "RichiestaFin", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public RichiestaFin RichiestaFin { get; set; }
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName = "xsd", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsd { get; set; }
[XmlAttribute(AttributeName = "soapenv", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soapenv { get; set; }
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
public Envelope()
{
ns.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");
}
}