Headers not being serialized correctly
See original GitHub issueHello, thank you for bringing SOAP to .NET Core! I am having a problem with [XmlAttribute] and [XmlElement] not being honored when serializing headers. Let’s say I have the following MyInterface class:
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.newtrade.com/expedia/R14/header")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.newtrade.com/expedia/R14/header", IsNullable = false)]
public class MyInterface
{
private string nameField;
private decimal versionField;
[System.Xml.Serialization.XmlAttributeAttribute("Name")]
public string Name
{
get { return this.nameField; }
set { this.nameField = value;}
}
[System.Xml.Serialization.XmlElement("Version")]
public decimal Version
{
get { return this.versionField; }
set { this.versionField = value; }
}
}
I am returning the same MyInterface object in a ResponseModel as both a header and a body:
[MessageContract(IsWrapped = false)]
public class ResponseModel
{
[MessageHeader(Name = "MyInterface", Namespace = "http://www.newtrade.com/expedia/R14/header")]
public MyInterface InterfaceAsHeader { get; set; }
[MessageBodyMember(Name = "MyInterface", Namespace = "http://www.newtrade.com/expedia/R14/header")]
public MyInterface InterfaceAsBody { get; set; }
}
This is the serialized result:
<s:Header>
<MyInterface xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.newtrade.com/expedia/R14/header">
<nameField xmlns = "http://schemas.datacontract.org/2004/07/MyContract" > ExpediaDirectConnect </ nameField >
<versionField xmlns = "http://schemas.datacontract.org/2004/07/MyContract" > 0 </ versionField >
</ MyInterface >
</ s:Header>
<s:Body>
<MyInterface Name = "ExpediaDirectConnect" xmlns="http://www.newtrade.com/expedia/R14/header">
< Version > 0 </ Version >
</ MyInterface >
</ s:Body>
Note that in the header the element names are the private member names vs those specified in [XmlAttribute] and [XmlElement]. Also Name is being serialized as an element but it has been specified as an [XmlAttribute]. The body is perfect, though.
Can you shed some light on this for me, please? Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Soapheader cannot be serialized
SoapHeader with DataContractAttribute or SerializableAttribute, or removing them from the derived type.' it kinda wants soapheader to be also ...
Read more >The [Serializable] header is not necessary for class JSON ...
Many tutorials show the [Serializable] header on classes that will be serialized, but I am successfully using the JsonUtilitiy.
Read more >unable to deserialize value httpheader
I found the correct HttpHeader which is getting serialized correctly. Below is the header value that I am passing in. { "$type":"SourceCode.
Read more >Serialization - Code Structure
Using this library entails including headers listed in this section. It should not be necessary to explictly include any other header files.
Read more >How to customize character encoding with System.Text.Json
To serialize all language sets without escaping, use UnicodeRanges.All. Serialize specific characters. An alternative is to specify individual ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
BOOM! That was exactly what I needed, working perfectly now and thanks so much.
For anyone else who lands here, the class now looks like this:
and the output is:
@kotovaleksandr That looks very promising, I will code it up and report back! Thank you!!