Fix #1161: response headers use DataContractSerializer on XmlSerializer endpoints#1187
Open
myobis wants to merge 2 commits into
Open
Fix #1161: response headers use DataContractSerializer on XmlSerializer endpoints#1187myobis wants to merge 2 commits into
myobis wants to merge 2 commits into
Conversation
Author
|
To be quite transparent, I used Claude AI to assist me in analyzing SoapCore and authoring this fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1161
Problem
When an endpoint is configured with
SoapSerializer.XmlSerializer, response headers built from[MessageHeader]-decorated members are nevertheless serialized throughDataContractSerializer. The WCF helperMessageHeader.CreateHeader(name, ns, value)used atSoapEndpointMiddleware.cs:626hard-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 newXmlSerializerMessageHeader(aMessageHeadersubclass usingCachedXmlSerializer).The DCS path is unchanged.
Tests
Two regression tests in
Issue1161Tests.csPOST SOAP requests withdefault-namespace and prefixed-namespace inbound headers, asserting HTTP 200,
no
InvalidDataContractException, and no DCS namespaces in the response.Both tests fail on
developHEAD before the fix commit and pass after.The rest of the test suite is unaffected.