SoapCore
SoapCore copied to clipboard
XmlNamespaceOverrides doesn't apply for Message Header
Current Behavior
- The configuraiton on
XmlNamespaceOverridesdoes not work on all elements of the Xml Response. - The element
Headerkeeps the default prefixes (e.g. "s"). - The elements
EnvelopeandBodyuses the configured prefixes.
<MY-CUSTOM-PREFIX:Envelope
xmlns:MY-CUSTOM-PREFIX="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<ExtraInfo xmlns="http://tempuri.org/">Time: 15.07.2022 20:16:59</ExtraInfo>
</s:Header>
<MY-CUSTOM-PREFIX:Body>
<MainInfo xmlns="http://tempuri.org/">This is the request</MainInfo>
</MY-CUSTOM-PREFIX:Body>
</MY-CUSTOM-PREFIX:Envelope>
Expected Behavior
-
XmlNamespaceOverridesshould apply for the elementsEnvelope,BodyandHeader
Proposed Solution
- On
CustomMessage, overrideOnWriteStartHeadersthe same way done onOnWriteStartBody
<MY-CUSTOM-PREFIX:Envelope
xmlns:MY-CUSTOM-PREFIX="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MY-CUSTOM-PREFIX:Header>
<ExtraInfo xmlns="http://tempuri.org/">Time: 15.07.2022 20:33:26</ExtraInfo>
</MY-CUSTOM-PREFIX:Header>
<MY-CUSTOM-PREFIX:Body>
<MainInfo xmlns="http://tempuri.org/">This is the request</MainInfo>
</MY-CUSTOM-PREFIX:Body>
</MY-CUSTOM-PREFIX:Envelope>
Hot to Reproduce
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSoapCore();
services.TryAddSingleton<ISampleService, SampleService>();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var nsOverrides = new XmlNamespaceManager(new NameTable());
nsOverrides.AddNamespace("MY-CUSTOM-PREFIX", "http://schemas.xmlsoap.org/soap/envelope/");
var options = new SoapEncoderOptions()
{
XmlNamespaceOverrides = nsOverrides,
};
app.UseMvc();
app.UseSoapEndpoint<ISampleService>($"/Sample.asmx", options, SoapSerializer.XmlSerializer);
}
ISampleService.cs
[ServiceContract]
public interface ISampleService
{
[OperationContract]
[return: MessageParameter(Name = "Sample")]
SampleMessage Process(string info);
}
SampleService.cs
public class SampleService : ISampleService
{
public SampleMessage Process(string info)
{
return new SampleMessage
{
Header = $"Time: {DateTime.Now}",
Body = info,
};
}
}
SampleMessage.cs
[MessageContract(IsWrapped = false)]
public class SampleMessage
{
[MessageHeader(Name = "ExtraInfo")]
public string Header { get; set; }
[MessageBodyMember(Name = "MainInfo")]
public string Body { get; set; }
}
SOAP Request
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<Process>
<info>This is the request</info>
</Process>
</soapenv:Body>
</soapenv:Envelope>