Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions src/SoapCore.Tests/RawRequestSoap12Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,56 @@ public void Soap12PingWithActionInHeader()
}
}

[TestMethod]
public void Soap12PingWithNamespaceDeclarationsRepeatedOnBody()
{
var body = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
<soap12:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
<Ping xmlns=""http://tempuri.org/"">
<s>abc</s>
</Ping>
</soap12:Body>
</soap12:Envelope>
";
var bodyBytes = Encoding.UTF8.GetBytes(body);
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "application/soap+xml"))
{
content.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("action", "\"http://tempuri.org/ITestService/Ping\""));
using (var res = host.CreateRequest("/Service.svc").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();
}
}
}

[TestMethod]
public void Soap12PingWithPrefixShadowedOnBody()
{
var body = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap12:Envelope xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"" xmlns:tns=""http://example.org/not-tempuri"">
<soap12:Body xmlns:tns=""http://tempuri.org/"">
<tns:Ping>
<tns:s>abc</tns:s>
</tns:Ping>
</soap12:Body>
</soap12:Envelope>
";
var bodyBytes = Encoding.UTF8.GetBytes(body);
using (var host = CreateTestHost())
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "application/soap+xml"))
{
content.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("action", "\"http://tempuri.org/ITestService/Ping\""));
using (var res = host.CreateRequest("/Service.svc").And(msg => msg.Content = content).PostAsync().Result)
{
res.EnsureSuccessStatusCode();
}
}
}

[TestMethod]
public void Soap12PingWithActionInEnvelopeHeader()
{
Expand Down Expand Up @@ -253,8 +303,8 @@ public async Task Soap12DetailedFault()
ExceptionProperty = "Detail message"
});
}
}
}

[TestMethod]
public async Task Soap12InvalidSchema()
{
Expand Down
7 changes: 5 additions & 2 deletions src/SoapCore/ParsedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ private static (XDocument, bool isEmpty) ExtractSoapBody(XDocument envelope, Mes
return (new XDocument(), true);
}

var rootAttributes = root.Attributes();
// The envelope attributes are carried onto the body so that it keeps its namespace bindings once it is
// detached. An attribute the body already declares has to win: XAttribute does not override equality, so
// Union compares by reference and a declaration present on both elements would be added twice and throw.
var bodyAttributes = bodyNode.Attributes();
var allAttributes = bodyAttributes.Union(rootAttributes);
var rootAttributes = root.Attributes().Where(attribute => bodyNode.Attribute(attribute.Name) == null);
var allAttributes = bodyAttributes.Concat(rootAttributes).ToList();
bodyNode.ReplaceAttributes(allAttributes);

//return new XDocument(bodyNode.Elements().FirstOrDefault());
Expand Down
Loading