开发者

Attributes and elements missing from serialized object

开发者 https://www.devze.com 2023-01-06 07:37 出处:网络
I have some generated proxy classes, that contain properties with the XMLAttribute attribute, e.g. [System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, Name

I have some generated proxy classes, that contain properties with the XMLAttribute attribute, e.g.

[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://www.egem.nl/StUF/StUF0301")]
public Verwerkingssoort verwerkingssoort
{
    get
    {
        return this.verwerkingssoortField;
    }
    set
    {
        this.verwerkingssoortField = value;
    }
}

This and several other properties don't show up in the SOAP message however. The proxies were generated using svcutil.

As I'm writing this question I notice that the properties that do show up as attributes are strings, while this is an Enum (but I haven't done a thorough check, yet). Does somebody know if this is the problem, or what else it could be and what possible solutions there are?

Update: After some more checking, I found that no Enums are included as attribute, but Strings and Bools work fine.

Update 2: In a simple case an Enum as attribute is serialized just fine.

Update 3: If I replace XmlAttributeAttribute(...) with XmlIgnoreAttribute() and add the following property:

[System.Xml.Serialization.XmlAttributeAttribute("verwerkingssoort")]
public string verwerkingssoortString
{
    get
    {
        return this.verwerkingssoortField.ToString();
    }
    set
    {
        thi开发者_如何学JAVAs.verwerkingssoortField = (Verwerkingssoort)System.Enum.Parse(typeof(Verwerkingssoort), value, true);
    }
}

it works fine, but making changes like this throughout the generated code would be a rather Herculean task, and when the contract changes, I would need to do it all over again. So I'm still looking for a better solution.

Update 4: It turns out that this problem is not limited to attributes. I just noticed that a property that should be serialized to an element is omitted as well. The same things apply: it is an Enum, and it works fine if I change it to a string.

Thanks, regards,

Miel.


Have you tried setting Type property of the XmlAttributeAttribute class to the type of your enum?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号