I have to implement a SOAP call with a JSON object that comes from our frontend which is obtained by a JSON Schema that is translated from an XSD schema of a SOAP service. We have already implemented a translation between this JSON we receive and the corresponding XML and we are able to serialize and deserialize c# class of this SOAP service.
The main problem that we are now facing is that the JSON properties are not fixed in order, but the SOAP class have a defined order and the XML tag that don't comes in the right position are not serialized. I have tried to implement this solution in order to override the default XmlElement
attributes that comes to the SOAP reference and for some classes this is working well.
Unfortunately, we are unable to create an XmlSerializer
for types that have at last one property with the XmlChoiceIdentifierAttribute
defined, like this one:
public partial class CUAA
{
private string itemField;
private ItemChoiceType itemElementNameField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("PersonaFisica", typeof(string), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("PersonaGiuridica", typeof(string), Order=0)]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public string Item
{
get
{
return this.itemField;
}
set
{
this.itemField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName
{
get
{
return this.itemElementNameField;
}
set
{
this.itemElementNameField = value;
}
}
}
If we try to use override for a class that contains this attribute we got this error:
You need to add XmlChoiceIdentifierAttribute to the 'Item' member
I have looked inside XmlAttributes
class reference, I've found that the class have a property XmlChoiceIdentifier
that could contains the attribute but it's a read-only prop and seems to me that this prop is always null
.
There is any way to make this override work, or to add this attribute to the override?