Null value node is causing deserialization problems

Discussion in 'ASP .Net Web Services' started by yads12@gmail.com, Oct 10, 2006.

  1. Guest

    Let's say I have the following wsdl snipet:

    <s:complexType name="consumer_response_info">
    <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="final_score"
    type="tns:final_score" />
    <s:element minOccurs="0" maxOccurs="1" name="app_score"
    type="tns:app_score" />
    <s:element minOccurs="0" maxOccurs="1" name="num_blank_chars"
    type="tns:num_blank_chars" />
    </s:sequence>
    </s:complexType>
    <s:complexType name="final_score" mixed="true">
    <s:sequence>
    <s:any minOccurs="0" maxOccurs="1" />
    </s:sequence>
    </s:complexType>
    <s:complexType name="app_score" mixed="true">
    <s:sequence>
    <s:any minOccurs="0" maxOccurs="1" />
    </s:sequence>
    </s:complexType>
    <s:complexType name="num_blank_chars" mixed="true">
    <s:sequence>
    <s:any minOccurs="0" maxOccurs="1" />
    </s:sequence>
    </s:complexType>

    Which generates the following class
    public partial class consumer_response_info {
    private System.Xml.XmlNode final_scoreField;
    private System.Xml.XmlNode app_scoreField;

    /// <remarks/>
    public System.Xml.XmlNode final_score {
    get {
    return this.final_scoreField;
    }
    set {
    this.final_scoreField = value;
    }
    }

    /// <remarks/>
    public System.Xml.XmlNode app_score {
    get {
    return this.app_scoreField;
    }
    set {
    this.app_scoreField = value;
    }
    }

    /// <remarks/>
    public System.Xml.XmlNode num_blank_chars {
    get {
    return this.num_blank_charsField;
    }
    set {
    this.num_blank_charsField = value;
    }
    }
    }

    If the following xml is passed from the webservice:
    <consumer_response_info>
    <final_score>998</final_score>
    <app_score>100</app_score>
    <num_blank_chars>0</num_blank_chars>
    </consumer_response_info>

    everything works fine and is deserialized properly.

    If however the final_score element is null:
    <consumer_response_info>
    <final_score />
    <app_score>100</app_score>
    <num_blank_chars>0</num_blank_chars>
    </consumer_response_info>

    The deserialization comes back with the object having app_score and
    num_blank_chars values of null and the OuterXml value of final_score is
    "<app_score>100</app_score>". So it seems to just ignore the null value
    of final_score and populate the next node (in this case app_score) as
    an element inside the final_score node. Incidently it also fails to
    parse anymore of the document.

    Furthermore, final_score, app_score, and num_blank_chars have their own
    types (with the same name) on the server side, for some reason the
    Visual Studio autogenerated classes mark them as type XmlNode. Not sure
    if that's important or not.

    Does anybody know why it's failing like this and any potential
    solutions to the problem?
    , Oct 10, 2006
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Let's say I have the following wsdl snipet:
    >
    > <s:complexType name="consumer_response_info">
    > <s:sequence>
    > <s:element minOccurs="0" maxOccurs="1" name="final_score"
    > type="tns:final_score" />
    > <s:element minOccurs="0" maxOccurs="1" name="app_score"
    > type="tns:app_score" />
    > <s:element minOccurs="0" maxOccurs="1" name="num_blank_chars"
    > type="tns:num_blank_chars" />
    > </s:sequence>
    > </s:complexType>
    > <s:complexType name="final_score" mixed="true">
    > <s:sequence>
    > <s:any minOccurs="0" maxOccurs="1" />
    > </s:sequence>
    > </s:complexType>
    > <s:complexType name="app_score" mixed="true">
    > <s:sequence>
    > <s:any minOccurs="0" maxOccurs="1" />
    > </s:sequence>
    > </s:complexType>
    > <s:complexType name="num_blank_chars" mixed="true">
    > <s:sequence>
    > <s:any minOccurs="0" maxOccurs="1" />
    > </s:sequence>
    > </s:complexType>
    >
    > Which generates the following class
    > public partial class consumer_response_info {
    > private System.Xml.XmlNode final_scoreField;
    > private System.Xml.XmlNode app_scoreField;
    >
    > /// <remarks/>
    > public System.Xml.XmlNode final_score {
    > get {
    > return this.final_scoreField;
    > }
    > set {
    > this.final_scoreField = value;
    > }
    > }
    >
    > /// <remarks/>
    > public System.Xml.XmlNode app_score {
    > get {
    > return this.app_scoreField;
    > }
    > set {
    > this.app_scoreField = value;
    > }
    > }
    >
    > /// <remarks/>
    > public System.Xml.XmlNode num_blank_chars {
    > get {
    > return this.num_blank_charsField;
    > }
    > set {
    > this.num_blank_charsField = value;
    > }
    > }
    > }
    >
    > If the following xml is passed from the webservice:
    > <consumer_response_info>
    > <final_score>998</final_score>
    > <app_score>100</app_score>
    > <num_blank_chars>0</num_blank_chars>
    > </consumer_response_info>
    >
    > everything works fine and is deserialized properly.
    >
    > If however the final_score element is null:
    > <consumer_response_info>
    > <final_score />
    > <app_score>100</app_score>
    > <num_blank_chars>0</num_blank_chars>
    > </consumer_response_info>
    >
    > The deserialization comes back with the object having app_score and
    > num_blank_chars values of null and the OuterXml value of final_score is
    > "<app_score>100</app_score>". So it seems to just ignore the null value
    > of final_score and populate the next node (in this case app_score) as
    > an element inside the final_score node. Incidently it also fails to
    > parse anymore of the document.
    >
    > Furthermore, final_score, app_score, and num_blank_chars have their own
    > types (with the same name) on the server side, for some reason the
    > Visual Studio autogenerated classes mark them as type XmlNode. Not sure
    > if that's important or not.
    >
    > Does anybody know why it's failing like this and any potential
    > solutions to the problem?


    xs:any is causing XmlNode.

    I don't know if it's your null problem, but why have mixed="true" if you've
    only got elements inside and no text?

    John
    John Saunders, Oct 11, 2006
    #2
    1. Advertising

  3. Guest

    John Saunders wrote:
    >
    > xs:any is causing XmlNode.
    >
    > I don't know if it's your null problem, but why have mixed="true" if you've
    > only got elements inside and no text?
    >
    > John


    This is the autogenerated wsdl file from the webservice that we
    created. We do only have text inside the elements. Regardless why would
    xmlnode deserialize the xml incorrectly?
    , Oct 11, 2006
    #3
  4. <> wrote in message
    news:...
    >
    > John Saunders wrote:
    >>
    >> xs:any is causing XmlNode.
    >>
    >> I don't know if it's your null problem, but why have mixed="true" if
    >> you've
    >> only got elements inside and no text?
    >>
    >> John

    >
    > This is the autogenerated wsdl file from the webservice that we
    > created. We do only have text inside the elements. Regardless why would
    > xmlnode deserialize the xml incorrectly?


    I didn't say that it should do the wrong thing, only that mixed="true" might
    be what was instigating it to do so.

    You might try removing the mixed attribute just to see what happens...

    John
    John Saunders, Oct 11, 2006
    #4
  5. Guest

    I fixed the problem on the webservice end. Those classes all had an
    Item property that was an XmlNode and had an XmlAnyElementAttribute. I
    changed the XmlAnyElementAttribute to
    XmlElementAttribute(IsNullable=true) and the deserialization now works
    correctly.

    wrote:
    > Let's say I have the following wsdl snipet:
    >
    > <s:complexType name="consumer_response_info">
    > <s:sequence>
    > <s:element minOccurs="0" maxOccurs="1" name="final_score"
    > type="tns:final_score" />
    > <s:element minOccurs="0" maxOccurs="1" name="app_score"
    > type="tns:app_score" />
    > <s:element minOccurs="0" maxOccurs="1" name="num_blank_chars"
    > type="tns:num_blank_chars" />
    > </s:sequence>
    > </s:complexType>
    > <s:complexType name="final_score" mixed="true">
    > <s:sequence>
    > <s:any minOccurs="0" maxOccurs="1" />
    > </s:sequence>
    > </s:complexType>
    > <s:complexType name="app_score" mixed="true">
    > <s:sequence>
    > <s:any minOccurs="0" maxOccurs="1" />
    > </s:sequence>
    > </s:complexType>
    > <s:complexType name="num_blank_chars" mixed="true">
    > <s:sequence>
    > <s:any minOccurs="0" maxOccurs="1" />
    > </s:sequence>
    > </s:complexType>
    >
    > Which generates the following class
    > public partial class consumer_response_info {
    > private System.Xml.XmlNode final_scoreField;
    > private System.Xml.XmlNode app_scoreField;
    >
    > /// <remarks/>
    > public System.Xml.XmlNode final_score {
    > get {
    > return this.final_scoreField;
    > }
    > set {
    > this.final_scoreField = value;
    > }
    > }
    >
    > /// <remarks/>
    > public System.Xml.XmlNode app_score {
    > get {
    > return this.app_scoreField;
    > }
    > set {
    > this.app_scoreField = value;
    > }
    > }
    >
    > /// <remarks/>
    > public System.Xml.XmlNode num_blank_chars {
    > get {
    > return this.num_blank_charsField;
    > }
    > set {
    > this.num_blank_charsField = value;
    > }
    > }
    > }
    >
    > If the following xml is passed from the webservice:
    > <consumer_response_info>
    > <final_score>998</final_score>
    > <app_score>100</app_score>
    > <num_blank_chars>0</num_blank_chars>
    > </consumer_response_info>
    >
    > everything works fine and is deserialized properly.
    >
    > If however the final_score element is null:
    > <consumer_response_info>
    > <final_score />
    > <app_score>100</app_score>
    > <num_blank_chars>0</num_blank_chars>
    > </consumer_response_info>
    >
    > The deserialization comes back with the object having app_score and
    > num_blank_chars values of null and the OuterXml value of final_score is
    > "<app_score>100</app_score>". So it seems to just ignore the null value
    > of final_score and populate the next node (in this case app_score) as
    > an element inside the final_score node. Incidently it also fails to
    > parse anymore of the document.
    >
    > Furthermore, final_score, app_score, and num_blank_chars have their own
    > types (with the same name) on the server side, for some reason the
    > Visual Studio autogenerated classes mark them as type XmlNode. Not sure
    > if that's important or not.
    >
    > Does anybody know why it's failing like this and any potential
    > solutions to the problem?
    , Oct 11, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,400
  2. Eddy C
    Replies:
    6
    Views:
    6,397
    Eddy C
    Oct 18, 2005
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,400
    Dimitre Novatchev
    Aug 24, 2006
  4. njsimha
    Replies:
    0
    Views:
    765
    njsimha
    Sep 16, 2008
  5. John Bankhead

    Null parent node on custom tree node after populate on demand

    John Bankhead, Dec 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    270
    John Bankhead
    Dec 4, 2006
Loading...

Share This Page