【问题标题】:Visual Studio 2019 WSDL how to use <any> elementVisual Studio 2019 WSDL 如何使用 <any> 元素
【发布时间】:2021-11-08 10:29:51
【问题描述】:

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

我不知道如何使用 OSDTextConfiguration 的“扩展”元素向 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");
    }
}

【问题讨论】:

    标签: c# visual-studio wsdl onvif


    【解决方案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;
      }
    

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 2020-03-04
      • 2021-05-13
      • 1970-01-01
      • 2021-07-16
      • 2021-05-26
      • 2021-09-03
      • 1970-01-01
      • 2020-12-31
      相关资源
      最近更新 更多