2012-03-12 2 views
0

Я выдаю с доступ к собственности моего сгенерированного класса.Доступ к классу, сгенерированному с помощью XSD

Это мой XML:

<?xml version="1.0" encoding="UTF-8"?> 
<e:Envelope xmlns:e="http://www.w3.org/2003/05/soap-envelope" 
xmlns:w="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" 
xmlns:dn="http://www.onvif.org/ver10/network/wsdl"> 
    <e:Header> 
    <w:MessageID>uuid:84ede3de-7dec-11d0-c360-f</w:MessageID> 
    <w:To e:mustUnderstand="true">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To> 
    <w:Action mustUnderstand="true"> 
     http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe 
    </w:Action> 
    </e:Header> 
    <e:Body> 
    <d:Probe> 
     <d:Scopes></d:Scopes> 
     <d:Types>dn:NetworkVideoTransmitter</d:Types> 
    </d:Probe> 
    </e:Body> 
</e:Envelope> 

Это мой генерироваться XSD (один из трех):

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="Envelope" targetNamespace="http://www.w3.org/2003/05/soap-envelope" 
xmlns:mstns="http://www.w3.org/2003/05/soap-envelope" 
xmlns="http://www.w3.org/2003/05/soap-envelope" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft 
com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" 
xmlns:app1="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:app2="http://schemas.xmlsoap.org/ws/2005/04/discovery"> 
    <xs:import namespace="http://schemas.xmlsoap.org/ws/2005/04/discovery" schemaLocation="Probe_app2.xsd" /> 
    <xs:import namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing" schemaLocation="Probe_app1.xsd" /> 
    <xs:attribute name="mustUnderstand" msdata:Prefix="e" type="xs:string" /> 
    <xs:element name="Envelope" msdata:IsDataSet="true" msdata:Locale="en-US" msdata:Prefix="e"> 
    <xs:complexType> 
     <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element name="Header" msdata:Prefix="e"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element ref="app1:MessageID" minOccurs="0" /> 
        <xs:element ref="app1:To" /> 
       <xs:element ref="app1:Action" /> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     <xs:element name="Body" msdata:Prefix="e"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element ref="app2:Probe" /> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     </xs:choice> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

И, наконец, это мой сгенерированный класс от xsd2code:

namespace PROBE 
{ 
using System; 
using System.Diagnostics; 
using System.Xml.Serialization; 
using System.Collections; 
using System.Xml.Schema; 
using System.ComponentModel; 
using System.IO; 
using System.Text; 
using System.Collections.Generic; 


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2003/05/soap-envelope")] 
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.w3.org/2003/05/soap-envelope", IsNullable = false)] 
public partial class Envelope 
{ 

    private List<object> itemsField; 

    private static System.Xml.Serialization.XmlSerializer serializer; 

    public Envelope() 
    { 
     this.itemsField = new List<object>(); 
    } 

    [System.Xml.Serialization.XmlElementAttribute("Body", typeof(EnvelopeBody), Order = 0)] 
    [System.Xml.Serialization.XmlElementAttribute("Header", typeof(EnvelopeHeader), Order = 0)] 
    public List<object> Items 
    { 
     get 
     { 
      return this.itemsField; 
     } 
     set 
     { 
      this.itemsField = value; 
     } 
    } 

    private static System.Xml.Serialization.XmlSerializer Serializer 
    { 
     get 
     { 
      if ((serializer == null)) 
      { 
       serializer = new System.Xml.Serialization.XmlSerializer(typeof(Envelope)); 
      } 
      return serializer; 
     } 
    } 
} 

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2003/05/soap-envelope")] 
public partial class EnvelopeBody 
{ 

    private Probe probeField; 

    private static System.Xml.Serialization.XmlSerializer serializer; 

    public EnvelopeBody() 
    { 
     this.probeField = new Probe(); 
    } 

    [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2005/04/discovery", Order = 0)] 
    public Probe Probe 
    { 
     get 
     { 
      return this.probeField; 
     } 
     set 
     { 
      this.probeField = value; 
     } 
    } 

    private static System.Xml.Serialization.XmlSerializer Serializer 
    { 
     get 
     { 
      if ((serializer == null)) 
      { 
       serializer = new System.Xml.Serialization.XmlSerializer(typeof(EnvelopeBody)); 
      } 
      return serializer; 
     } 
    } 
} 

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/ws/2005/04/discovery")] 
public partial class Probe 
{ 

    private string scopesField; 

    private string typesField; 

    private static System.Xml.Serialization.XmlSerializer serializer; 

    [System.Xml.Serialization.XmlElementAttribute(Order = 0)] 
    public string Scopes 
    { 
     get 
     { 
      return this.scopesField; 
     } 
     set 
     { 
      this.scopesField = value; 
     } 
    } 

    [System.Xml.Serialization.XmlElementAttribute(Order = 1)] 
    public string Types 
    { 
     get 
     { 
      return this.typesField; 
     } 
     set 
     { 
      this.typesField = value; 
     } 
    } 

    private static System.Xml.Serialization.XmlSerializer Serializer 
    { 
     get 
     { 
      if ((serializer == null)) 
      { 
       serializer = new System.Xml.Serialization.XmlSerializer(typeof(Probe)); 
      } 
      return serializer; 
     } 
    } 
} 

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2003/05/soap-envelope")] 
public partial class EnvelopeHeader 
{ 

    private string messageIDField; 

    private To toField; 

    private Action actionField; 

    private static System.Xml.Serialization.XmlSerializer serializer; 

    public EnvelopeHeader() 
    { 
     this.actionField = new Action(); 
     this.toField = new To(); 
    } 

    [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing", Order = 0)] 
    public string MessageID 
    { 
     get 
     { 
      return this.messageIDField; 
     } 
     set 
     { 
      this.messageIDField = value; 
     } 
    } 

    [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing", IsNullable = true, Order = 1)] 
    public To To 
    { 
     get 
     { 
      return this.toField; 
     } 
     set 
     { 
      this.toField = value; 
     } 
    } 

    [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing", IsNullable = true, Order = 2)] 
    public Action Action 
    { 
     get 
     { 
      return this.actionField; 
     } 
     set 
     { 
      this.actionField = value; 
     } 
    } 

    private static System.Xml.Serialization.XmlSerializer Serializer 
    { 
     get 
     { 
      if ((serializer == null)) 
      { 
       serializer = new System.Xml.Serialization.XmlSerializer(typeof(EnvelopeHeader)); 
      } 
      return serializer; 
     } 
    } 
} 

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing")] 
public partial class To 
{ 

    private string mustUnderstandField; 

    private string valueField; 

    private static System.Xml.Serialization.XmlSerializer serializer; 

    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/2003/05/soap-envelope")] 
    public string mustUnderstand 
    { 
     get 
     { 
      return this.mustUnderstandField; 
     } 
     set 
     { 
      this.mustUnderstandField = value; 
     } 
    } 

    [System.Xml.Serialization.XmlTextAttribute()] 
    public string Value 
    { 
     get 
     { 
      return this.valueField; 
     } 
     set 
     { 
      this.valueField = value; 
     } 
    } 

    private static System.Xml.Serialization.XmlSerializer Serializer 
    { 
     get 
     { 
      if ((serializer == null)) 
      { 
       serializer = new System.Xml.Serialization.XmlSerializer(typeof(To)); 
      } 
      return serializer; 
     } 
    } 
} 

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing")] 
public partial class Action 
{ 

    private string mustUnderstandField; 

    private string valueField; 

    private static System.Xml.Serialization.XmlSerializer serializer; 

    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string mustUnderstand 
    { 
     get 
     { 
      return this.mustUnderstandField; 
     } 
     set 
     { 
      this.mustUnderstandField = value; 
     } 
    } 

    [System.Xml.Serialization.XmlTextAttribute()] 
    public string Value 
    { 
     get 
     { 
      return this.valueField; 
     } 
     set 
     { 
      this.valueField = value; 
     } 
    } 

    private static System.Xml.Serialization.XmlSerializer Serializer 
    { 
     get 
     { 
      if ((serializer == null)) 
      { 
       serializer = new System.Xml.Serialization.XmlSerializer(typeof(Action)); 
      } 
      return serializer; 
     } 
    } 
} 
} 

У меня нет проблем с Deserialization, он создал правильный класс, но я не знаю, как acc acc свойства. я пытался что-то вроде этого:

PROBE.Envelope env = PROBE.Envelope.Deserialize(xmlString); 
env.Items[0].MessageID = "xxxxxxxxxxx"; 

, но это неправильно.

( Ошибка 33 'объект' не содержит определения для 'MessageID', и не может быть найден метод расширения 'MessageID', принимающий первый аргумент типа 'object' (если вам не указана директива using или ссылка на сборку ?))

Я включил link в изображение для лучшего понимания структуры класса. Буду благодарен за любой совет, спасибо.

ответ

1

По какой-то причине ваше имущество Items относится к типу объекта, но должно быть EnvelopeHeader. Проверьте свой xsd-файл, если вы правильно определили все типы.

Или вы можете бросить:

((EnvelopeHeader)env.Items[0]).MessageID = "xxxxxxxxxxx"; 
+0

Да, я думаю, что это нормально, потому что Пункт [0] является EnvelopeHeader типа и пункт [1] является EnvelopeBody типа ... – Hyen

+0

Ааа да, спасибо! – Hyen

Смежные вопросы