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.
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.
<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
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. 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'.
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;
}