question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XmlArrayItemAttribute is not honored

See original GitHub issue

I’m trying to port an existing .NET Framework WCF service to .NET Core using SOAP Core. Most of it seems to work as-is, which is great! But I just ran into an issue where the original service has an array of strings, but defines the name of the seperate items using an [XmlArryItem] attribute.

I’ve created a simple test service to illustrate the point.

Consider this Operation Contract:

[ServiceContract(Namespace ="urn:test:1")]
public interface ITestService
{
    [OperationContract]
    TestResult ExecuteFunction(string firstParameter, [XmlArrayItem("item")]string[] parameterArray);
}

And the result object (not important, but for completeness):

public class TestResult
{
    public string Message { get; set; }
}

This services uses the XmlSerializer:

app.UseSoapEndpoint<TestService>("/Test.svc", new BasicHttpBinding(), SoapSerializer.XmlSerializer, false);

The WSDL will look like this (displaying only the relevant part):

<xs:element name="ExecuteFunction">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="firstParameter" type="xs:string"/>
            <xs:element minOccurs="0" maxOccurs="1" name="parameterArray" type="tns:ArrayOfString"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType name="ArrayOfString">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" nillable="true" name="string" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfString" nillable="true" type="tns:ArrayOfString"/>

But with WCF, the WSDL would look like this (displaying only the array):

<xs:complexType name="ArrayOfString">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" nillable="true" name="item" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfString" nillable="true" type="tns:ArrayOfString"/>

Notice how the “name” of an individual array item is different.

I’ll try to see if I can track down the issue, fix it and submit a PR, but I have no idea where to start looking. So any pointers would be appreciated 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
paleocomburocommented, May 13, 2019

I’ve verified and it now works as expected. Thanks!

0reactions
paleocomburocommented, May 7, 2019

Cool, thanks! I see a lot of changes have been made so time to plan a re-evaluation 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serializing data using XmlArrayItemAttribute not working well
You can use CollectionDataContract instead. First, create a class: [CollectionDataContract(ItemName="CardNumber")] public class CardsList ...
Read more >
[Solved] Trying to add XML attribute overrides for an array ...
I have tried changing the attribute type from XmlArrayItemAttribute to XmlElementAttribute. To be honest, I can't remember all the combinations ...
Read more >
XmlArrayItemAttribute.IsNullable Property (System.Xml. ...
Gets or sets a value that indicates whether the XmlSerializer must serialize a member as an empty XML tag with the xsi:nil attribute...
Read more >
XML Serialization: handling a collection of different classes
The XmlSerializer does not honour the fact that Brass and Woodwind are both derived from Instrument.
Read more >
Deserializing XML Into A List Or Array Of Objects
If the object of this class were a property, then it would be marked, for example, with XmlElement attribute. But it's not an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found