-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #955 from bfcrmimick/Issue908
XmlNode/XmlElement as an Input Parameter
- Loading branch information
Showing
8 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
18 changes: 18 additions & 0 deletions
18
src/SoapCore.Tests/XmlNodeInputOutput/IXmlNodeInputOutput.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ServiceModel; | ||
using System.Text; | ||
using System.Xml; | ||
|
||
namespace SoapCore.Tests.XmlNodeInputOutput | ||
{ | ||
[ServiceContract] | ||
public interface IXmlNodeInputOutput | ||
{ | ||
[OperationContract] | ||
XmlElement ProcessRequest(string login, string password, XmlElement requestXml); | ||
|
||
[OperationContract] | ||
XmlElement GetRequest(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.IO; | ||
using System.ServiceModel.Channels; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace SoapCore.Tests.XmlNodeInputOutput | ||
{ | ||
public class Startup | ||
{ | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddSoapCore(); | ||
services.TryAddSingleton<IXmlNodeInputOutput, XmlNodeInputOutput>(); | ||
services.AddMvc(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseRouting(); | ||
|
||
app.UseEndpoints(x => | ||
{ | ||
x.UseSoapEndpoint<IXmlNodeInputOutput>("/Service.svc", new SoapEncoderOptions(), SoapSerializer.DataContractSerializer); | ||
x.UseSoapEndpoint<IXmlNodeInputOutput>("/Service.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer); | ||
}); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/SoapCore.Tests/XmlNodeInputOutput/XmlNodeInputOutput.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Xml; | ||
|
||
namespace SoapCore.Tests.XmlNodeInputOutput | ||
{ | ||
public class XmlNodeInputOutput : IXmlNodeInputOutput | ||
{ | ||
public XmlNodeInputOutput() | ||
{ | ||
} | ||
|
||
public XmlElement ProcessRequest(string login, string password, XmlElement requestXml) | ||
{ | ||
if (password == "Password") | ||
{ | ||
return requestXml; | ||
} | ||
else | ||
{ | ||
XmlDocument xdError = new XmlDocument(); | ||
xdError.LoadXml("<Error><Message>Incorrect Password</Message></Error>"); | ||
return xdError.DocumentElement; | ||
} | ||
} | ||
|
||
public XmlElement GetRequest() | ||
{ | ||
XmlDocument xdResponse = new XmlDocument(); | ||
xdResponse.LoadXml("<Response><Message>A response</Message></Response>"); | ||
return xdResponse.DocumentElement; | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/SoapCore.Tests/XmlNodeInputOutput/XmlNodeInputOutputTests.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace SoapCore.Tests.XmlNodeInputOutput | ||
{ | ||
/* | ||
* This test refers to issue https://github.com/DigDes/SoapCore/issues/908 | ||
* User has a service with an XmlNode parameter and the value sent to the function is always null. | ||
*/ | ||
|
||
[TestClass] | ||
public class XmlNodeInputOutputTests | ||
{ | ||
[TestMethod] | ||
public async Task SendXmlInputGetXmlOutputAsync() | ||
{ | ||
string xmlInput = "<Request><Input>Hello</Input><Type>Test</Type></Request>", | ||
strLogin = "Login", | ||
strPassword = "Password"; | ||
var body = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""> | ||
<soapenv:Body> | ||
<ProcessRequest xmlns=""http://tempuri.org/""> | ||
<login>{strLogin}</login> | ||
<password>{strPassword}</password> | ||
<requestXml>{xmlInput}</requestXml> | ||
</ProcessRequest> | ||
</soapenv:Body> | ||
</soapenv:Envelope> | ||
"; | ||
using (var host = CreateTestHost()) | ||
using (var client = host.CreateClient()) | ||
using (var content = new StringContent(body, Encoding.UTF8, "text/xml")) | ||
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""ProcessRequest""").And(msg => msg.Content = content).PostAsync().Result) | ||
{ | ||
res.EnsureSuccessStatusCode(); | ||
|
||
var response = await res.Content.ReadAsStringAsync(); | ||
|
||
//XML comes back as formatted, need to clear any newlines and replace any double spaces | ||
Assert.IsTrue(response.Replace(System.Environment.NewLine, string.Empty).Replace(" ", string.Empty).Contains(xmlInput)); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetXmlOutputAsync() | ||
{ | ||
var body = $@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""> | ||
<soapenv:Body> | ||
<GetRequest xmlns=""http://tempuri.org/""> | ||
</GetRequest> | ||
</soapenv:Body> | ||
</soapenv:Envelope> | ||
"; | ||
using (var host = CreateTestHost()) | ||
using (var client = host.CreateClient()) | ||
using (var content = new StringContent(body, Encoding.UTF8, "text/xml")) | ||
using (var res = host.CreateRequest("/Service.svc").AddHeader("SOAPAction", @"""GetRequest""").And(msg => msg.Content = content).PostAsync().Result) | ||
{ | ||
res.EnsureSuccessStatusCode(); | ||
|
||
var response = await res.Content.ReadAsStringAsync(); | ||
Assert.IsTrue(response.Contains("A response")); | ||
} | ||
} | ||
|
||
private TestServer CreateTestHost() | ||
{ | ||
var webHostBuilder = new WebHostBuilder() | ||
.UseStartup<Startup>(); | ||
return new TestServer(webHostBuilder); | ||
} | ||
} | ||
} |
This file contains 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