Configuration branch

This commit is contained in:
2025-10-11 09:44:08 -04:00
parent 0e59b296a3
commit b9a2709fd5
31 changed files with 1367 additions and 1057 deletions
+27 -48
View File
@@ -4,92 +4,71 @@ using System.Xml;
namespace Endpoint
{
/// <summary>
/// A SOAP webservice endpoint.
/// </summary>
public class SoapEndpoint : HttpEndpoint
{
private string _xpathNamespaces = string.Empty;
private Dictionary<string, string> _namespaceToUri;
/// <summary>
/// Gets or sets the xpath query for the html document
/// Gets the SOAP endpoint configuration.
/// </summary>
/// <value>The xpath query.</value>
public string XpathQuery { get; set; }
/// <value>The SOAP endpoint configuration.</value>
public SoapEndpointConfiguration SoapEndpointConfiguration
{
get { return (SoapEndpointConfiguration)_httpEndpointConfiguration; }
}
/// <summary>
/// Gets or sets the namespaces used in the xpath query
/// Initializes a new instance of the <see cref="HttpEndpoint"/> class.
/// </summary>
/// <value>The xpath namespaces.</value>
public string XpathNamespaces
/// <param name="config">The SoapEndpointConfiguration.</param>
public SoapEndpoint(SoapEndpointConfiguration config)
: base(config)
{
get { return _xpathNamespaces; }
set
if (!string.IsNullOrEmpty(SoapEndpointConfiguration.XpathNamespaces))
{
_xpathNamespaces = value;
if (string.IsNullOrEmpty(_xpathNamespaces)) return;
var split = _xpathNamespaces.Split(',');
string[] split = SoapEndpointConfiguration.XpathNamespaces.Split(',');
if (split.Length != 2)
throw new ArgumentException("Need a comma separated pair in XpathNamespaces.");
throw new ArgumentException("Need a comma separated pair in XpathNamespaces.", "config");
_namespaceToUri = new Dictionary<string, string>();
_namespaceToUri.Add(split[0], split[1]);
}
}
/// <summary>
/// Gets or sets the expected query results.
/// </summary>
/// <value>The expected query results.</value>
public string ExpectedXpathResult { get; set; }
/// <summary>
/// Gets or sets the SOAP action.
/// </summary>
/// <value>The post.</value>
public string SoapAction { get; set; }
/// <summary>
/// Gets or sets the SOAP request.
/// </summary>
/// <value>The post.</value>
public string SoapRequest { get; set; }
/// <summary>
/// Gets the current status result of the endpoint
/// </summary>
/// <returns>Status</returns>
public override Status GetStatus()
{
var baseStatus = base.GetStatus();
if (baseStatus != Status.Up) // if we can't even get to the webserver, no need to try and call a WS.
Status baseStatus = base.GetStatus();
if (baseStatus != Status.Up)
return baseStatus;
try
{
var headers = new Dictionary<string, string> {{"SOAPAction", SoapAction}};
Dictionary<string, string> headers = new Dictionary<string, string>
{{"SOAPAction", SoapEndpointConfiguration.SoapAction}};
var xml = new XmlDocument();
XmlDocument xml = new XmlDocument();
xml.LoadXml(GetUrlContent(Uri, "text/xml; charset=utf-8", SoapRequest, headers));
xml.LoadXml(GetUrlContent(SoapEndpointConfiguration.Uri, "text/xml; charset=utf-8", SoapEndpointConfiguration.SoapRequest, headers));
XmlNodeList nodes;
if (_namespaceToUri != null)
{
var nsMgr = new XmlNamespaceManager(xml.NameTable);
foreach (var namespaceToUri in _namespaceToUri)
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xml.NameTable);
foreach (KeyValuePair<string, string> namespaceToUri in _namespaceToUri)
{
nsMgr.AddNamespace(namespaceToUri.Key, namespaceToUri.Value);
}
nodes = xml.SelectNodes(XpathQuery, nsMgr);
nodes = xml.SelectNodes(SoapEndpointConfiguration.XpathQuery, nsMgr);
}
else
nodes = xml.SelectNodes(XpathQuery);
nodes = xml.SelectNodes(SoapEndpointConfiguration.XpathQuery);
//xml.Save(@"c:\soap.xml");
// xml.Save(@"c:\soap.xml");
// verify response has expected value
if (nodes == null || nodes.Count == 0)
@@ -97,11 +76,11 @@ namespace Endpoint
StatusDescription = "Couldn't find expected value in SOAP response";
return Status.Error;
}
var value = nodes[0].Value.Trim();
if (value != ExpectedXpathResult)
string value = nodes[0].Value.Trim();
if (value != SoapEndpointConfiguration.ExpectedXpathResult)
{
StatusDescription = String.Format("Result was: '{0}', was expecting '{1}'", value,
ExpectedXpathResult);
SoapEndpointConfiguration.ExpectedXpathResult);
return Status.Error;
}
}