dotnet / dotnet/wcf

svcutil generation - XmlElement vs XmlArray

Open
#3,654 14 comments 1 reaction 2 assignees Claimed by @StephenMolloy View on GitHub
priority 2 serialization
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

I am trying to generate a WSDL client for Workday's Revenue Management service, specifically [Get_Customer_Invoices](https://community.workday.com/sites/default/files/file-hosting/productionapi/Revenue_Management/v32.1/Get_Customer_Invoices.html) (links to WSDL and XSD on the page).

The XSD indicates that the `Get_Customer_Invoices_Response` element should have (among other things) zero or more `Response_Data` elements of type `Customer_Invoice_Response_DataType`, each containing zero or more `Customer_Invoice` elements of type `Customer_InvoiceType`.

The XML that is returned by the services looks like:
```xml
...

...



CUSTOMER_INVOICE-6-1
0
```

The code generated for the Response_Data property on Get_Customer_Invoices_ResponseType is:
```csharp
[System.Xml.Serialization.XmlArrayAttribute(Order=5)]
[System.Xml.Serialization.XmlArrayItemAttribute("Customer_Invoice", typeof(Customer_InvoiceType), IsNullable=false)]
public Customer_InvoiceType[][] Response_Data
{ // ...
```

First of all, it experiences the issues described by #1274. After applying the workaround (make it `typeof(Customer_InvoiceType[])`) I get back a response with no errors, but also no response data. If I mock up a response and serialize it as-generated, I get:
```xml





1
...
```

Note there is now a new level, ``. I'm not finding a way to adjust the XmlArrayAttribute to not emit that level. Instead, it appears the fix is to:
* Add the missing `Customer_Invoice_Response_DataType` with a `Customer_Invoice` property of type `Customer_InvoiceType[]`
* Change the Response_Data property to type `Customer_Invoice_Response_DataType[]`
* Flag both properties with `XmlElement` instead of `XmlArray` and `XmlArrayItem`.

I'm assuming this is intended as an optimization (avoid the extra serialization class), but it ends up breaking the results. I was hoping just to create a single client library with the generated API classes, but the final Reference.cs with only the WSDL files for the modules we use is nearly 35 MB, so not really something I want to fix that many times by hand (there are 652 instances of this issue with Response_Data properties alone, and I'm guessing the other properties would have similar issues).

I also checked with xsd.exe and svcutil.exe; the same optimization is used by all three.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.