Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlSerializer: WSDL for XmlAttribute fields does not set use="required" flag #1006

Closed
vidrenning opened this issue Feb 7, 2024 · 0 comments · Fixed by #1007
Closed

XmlSerializer: WSDL for XmlAttribute fields does not set use="required" flag #1006

vidrenning opened this issue Feb 7, 2024 · 0 comments · Fixed by #1007

Comments

@vidrenning
Copy link
Contributor

vidrenning commented Feb 7, 2024

The WSDL schema that is generated for fields or properties with the [XmlAttribute] attribute is not correct. It differs from the WSDL that is generated by a ASP.NET ASMX Web Service. Let's take a look at the following class:

public class AttributeType
{
    [XmlAttribute]
    public int IntProperty { get; set; }

    [XmlAttribute]
    public int OptionalIntProperty { get; set; }

    public bool ShouldSerializeOptionalIntProperty()
    {
        return OptionalIntProperty != 0;
    }
}

SoapCore will generate a WSDL, such as the following:

<xsd:attribute name="IntProperty" type="xsd:int" />
<xsd:attribute name="OptionalIntProperty" type="xsd:int" />

However the WSDL that is generated by ASMX Web Services in .NET Framework is different. It adds the use="required" attribute for value types (such as int), to indicate that they are required. The required attribute is added for all value types, except if the class defines a ShouldSerialize*() method, which makes the type optional again.

This is the how the generated WSDL should actually look:

<xsd:attribute name="IntProperty" type="xsd:int" use="required" />
<xsd:attribute name="OptionalIntProperty" type="xsd:int" />

This applies to the current version v1.1.0.42.

vidrenning added a commit to vidrenning/SoapCore that referenced this issue Feb 7, 2024
If a member has been annotated with the [XmlAttribute] attribute, and it
is a value type, such as int, it will get the use="required" attribute.
However if it has a ShouldSerialize*() method, then it is considered
optional and the use="required" attribute is not added.

Added a new test to verify this behavior.

Fixes DigDes#1006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant