简体   繁体   English

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

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

I'm consumning this ONVIF service: https://www.onvif.org/ver10/media/wsdl/media.wsdl using Visual Studio 2019, which automatically generates a client wrapper from the WSDL file.我正在使用这个 ONVIF 服务: https ://www.onvif.org/ver10/media/wsdl/media.wsdl 使用 Visual Studio 2019,它会自动从 WSDL 文件生成一个客户端包装器。

I cannot figure out how to use the 'Extension' element of OSDTextConfiguration to add an element to OSDTextConfiguration which has not been specified in the 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>

This is the full file where the types are defined: https://www.onvif.org/ver10/schema/onvif.xsd?ccc393&ccc393这是定义类型的完整文件: https : //www.onvif.org/ver10/schema/onvif.xsd?ccc393&ccc393

Visual Studio defined the code below, and I guess I should be able to use XmlAnyElementAttribute() to add my element, but I do not know how to do it. Visual Studio 定义了下面的代码,我想我应该能够使用 XmlAnyElementAttribute() 添加我的元素,但我不知道该怎么做。 Could anyone point me in the right direction?有人能指出我正确的方向吗?

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");
    }
}

I figured out a way to do this and post it here in case it's useful to someone else.我想出了一种方法来做到这一点并将其张贴在这里以防对其他人有用。 The function below inserts an element 'IsPersistent' with value '0' or '1'.下面的函数插入一个值为“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