繁体   English   中英

Visual Studio 2019 WSDL 如何使用<any>元素

[英]Visual Studio 2019 WSDL how to use <any> element

我正在使用这个 ONVIF 服务: https ://www.onvif.org/ver10/media/wsdl/media.wsdl 使用 Visual Studio 2019,它会自动从 WSDL 文件生成一个客户端包装器。

我不知道如何使用 OSDTextConfiguration 的“Extension”元素向 OSDTextConfiguration 添加一个未在 WSDL 中指定的元素。

<xs:complexType name="OSDTextConfiguration">
   ...
   <xs:element name="Extension" type="tt:OSDTextConfigurationExtension" minOccurs="0"/>
</xs:complexType>

<xs:complexType name="OSDTextConfigurationExtension">
    <xs:sequence>
        <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>   <!-- first Vendor then ONVIF -->
    </xs:sequence>
    <xs:anyAttribute processContents="lax"/>
</xs:complexType>

这是定义类型的完整文件: https : //www.onvif.org/ver10/schema/onvif.xsd?ccc393&ccc393

Visual Studio 定义了下面的代码,我想我应该能够使用 XmlAnyElementAttribute() 添加我的元素,但我不知道该怎么做。 有人能指出我正确的方向吗?

public partial class OSDConfigurationExtension : object, System.ComponentModel.INotifyPropertyChanged {

private System.Xml.XmlElement[] anyField;

private System.Xml.XmlAttribute[] anyAttrField;

/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
public System.Xml.XmlElement[] Any {
    get {
        return this.anyField;
    }
    set {
        this.anyField = value;
        this.RaisePropertyChanged("Any");
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
    get {
        return this.anyAttrField;
    }
    set {
        this.anyAttrField = value;
        this.RaisePropertyChanged("AnyAttr");
    }
}

我想出了一种方法来做到这一点并将其张贴在这里以防对其他人有用。 下面的函数插入一个值为“0”或“1”的元素“IsPersistent”。

  internal static void SetOverlayPersistent(bool isPesistent, OSDConfiguration osd)
  {
     osd.Extension = new OSDConfigurationExtension();
     System.Xml.XmlDocument xmlDoc2 = new System.Xml.XmlDocument();
     System.Xml.XmlElement elem = xmlDoc2.CreateElement("IsPersistent", "http://www.onvif.org/ver10/schema");
     elem.InnerText = isPesistent ? "1" : "0";
     osd.Extension.Any = new System.Xml.XmlElement[1];
     osd.Extension.Any[0] = elem;
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM