|
1 | 1 | using System.Net.Http;
|
| 2 | +using System.Net.Http.Headers; |
2 | 3 | using System.Text;
|
3 | 4 | using System.Threading.Tasks;
|
4 | 5 | using Microsoft.AspNetCore.Hosting;
|
@@ -55,6 +56,66 @@ public async Task Soap11Ping()
|
55 | 56 | }
|
56 | 57 | }
|
57 | 58 |
|
| 59 | + [TestMethod] |
| 60 | + public void Soap11PingWithMixedNamespacing() |
| 61 | + { |
| 62 | + var pingValue = "Lorem ipsum"; |
| 63 | + var body = $@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?> |
| 64 | +<SOAP-ENV:Envelope xmlns:SOAPSDK1=""http://www.w3.org/2001/XMLSchema"" |
| 65 | + xmlns:SOAPSDK2=""http://www.w3.org/2001/XMLSchema-instance"" |
| 66 | + xmlns:SOAPSDK3=""http://schemas.xmlsoap.org/soap/encoding/"" |
| 67 | + xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/""> |
| 68 | + <SOAP-ENV:Body SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> |
| 69 | + <SOAPSDK4:Ping xmlns:SOAPSDK4=""http://tempuri.org/""> |
| 70 | + <s>{pingValue}</s> |
| 71 | + </SOAPSDK4:Ping> |
| 72 | + </SOAP-ENV:Body> |
| 73 | +</SOAP-ENV:Envelope> |
| 74 | +"; |
| 75 | + using (var host = CreateTestHost()) |
| 76 | + using (var client = host.CreateClient()) |
| 77 | + using (var content = new StringContent(body, Encoding.UTF8, "text/xml")) |
| 78 | + using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""Ping""").And(msg => msg.Content = content).PostAsync().Result) |
| 79 | + { |
| 80 | + res.EnsureSuccessStatusCode(); |
| 81 | + |
| 82 | + var response = res.Content.ReadAsStringAsync().Result; |
| 83 | + Assert.IsTrue(response.Contains(pingValue)); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + [TestMethod] |
| 88 | + public async Task Soap11PingInMultipart() |
| 89 | + { |
| 90 | + var pingValue = "abc"; |
| 91 | + var soapBody = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""> |
| 92 | + <soapenv:Body> |
| 93 | + <Ping xmlns=""http://tempuri.org/""> |
| 94 | + <s>{pingValue}</s> |
| 95 | + </Ping> |
| 96 | + </soapenv:Body> |
| 97 | + </soapenv:Envelope>"; |
| 98 | + |
| 99 | + using var host = CreateTestHost(); |
| 100 | + using var client = host.CreateClient(); |
| 101 | + using var multipartContent = new MultipartContent("related"); |
| 102 | + multipartContent.Headers.ContentType!.Parameters.Add(new NameValueHeaderValue("type", "\"text/xml\"")); |
| 103 | + |
| 104 | + using var soapContent = new StringContent(soapBody, Encoding.UTF8, "text/xml"); |
| 105 | + soapContent.Headers.Add("SOAPAction", @"""Ping"""); |
| 106 | + |
| 107 | + using var extraContent = new StringContent("some text payload", Encoding.UTF8, "text/plain"); |
| 108 | + |
| 109 | + multipartContent.Add(soapContent); |
| 110 | + multipartContent.Add(extraContent); |
| 111 | + |
| 112 | + using var res = await host.CreateRequest("/Service.svc").And(msg => msg.Content = multipartContent).PostAsync(); |
| 113 | + |
| 114 | + res.EnsureSuccessStatusCode(); |
| 115 | + var response = await res.Content.ReadAsStringAsync(); |
| 116 | + Assert.IsTrue(response.Contains(pingValue)); |
| 117 | + } |
| 118 | + |
58 | 119 | private TestServer CreateTestHost()
|
59 | 120 | {
|
60 | 121 | var webHostBuilder = new WebHostBuilder()
|
|
0 commit comments