Y
yads12
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?
<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?