Skip to content

Fix #1161: response headers use DataContractSerializer on XmlSerializer endpoints#1187

Open
myobis wants to merge 2 commits into
DigDes:developfrom
myobis:myobis/fix-1161-xmlattribute-serialization
Open

Fix #1161: response headers use DataContractSerializer on XmlSerializer endpoints#1187
myobis wants to merge 2 commits into
DigDes:developfrom
myobis:myobis/fix-1161-xmlattribute-serialization

Conversation

@myobis
Copy link
Copy Markdown

@myobis myobis commented May 21, 2026

Fixes #1161

Problem

When an endpoint is configured with SoapSerializer.XmlSerializer, response headers built from [MessageHeader]-decorated members are nevertheless serialized through DataContractSerializer. The WCF helper MessageHeader.CreateHeader(name, ns, value) used at SoapEndpointMiddleware.cs:626 hard-codes DCS internally; it does not respect the endpoint's serializer choice.

=> When the header type contains an [XmlAnyAttribute] XmlAttribute[] member with values, DCS throws InvalidDataContractException` and the endpoint returns HTTP 500.

The crash became visible in 1.2.1.0 because the rewritten inbound header reader populates [XmlAnyAttribute] arrays faithfully; earlier versions discarded that data, so DCS had nothing to choke on. The underlying write-side bug is older.

Fix

When _options.SoapSerializer == XmlSerializer, wrap the value in a new
XmlSerializerMessageHeader (a MessageHeader subclass using CachedXmlSerializer).
The DCS path is unchanged.

Tests

Two regression tests in Issue1161Tests.cs POST SOAP requests with
default-namespace and prefixed-namespace inbound headers, asserting HTTP 200,
no InvalidDataContractException, and no DCS namespaces in the response.

Both tests fail on develop HEAD before the fix commit and pass after.
The rest of the test suite is unaffected.

@myobis
Copy link
Copy Markdown
Author

myobis commented May 21, 2026

To be quite transparent, I used Claude AI to assist me in analyzing SoapCore and authoring this fix.
This being said, I can advocate each byte in the PR.

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 this pull request may close these issues.

Exception when deserializing the result message after updating SoapCore

1 participant