From dfe17fa9379890ac55b861219a897bdca0196713 Mon Sep 17 00:00:00 2001 From: "VIMPELCOM_MAIN\\NKuksov" Date: Wed, 9 Oct 2024 12:06:12 +0300 Subject: [PATCH] Fix wsdl from file import/include schemaLocation generating --- .../WsdlFromFile/WSDL/SnapshotPull.wsdl | 11 +++---- .../WsdlFromFile/WsdlIncludeTests.cs | 6 ++-- src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs | 6 +++- src/SoapCore/Meta/MetaFromFile.cs | 30 ++++++++++--------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/SoapCore.Tests/WsdlFromFile/WSDL/SnapshotPull.wsdl b/src/SoapCore.Tests/WsdlFromFile/WSDL/SnapshotPull.wsdl index 0333dbca..cdac20d0 100644 --- a/src/SoapCore.Tests/WsdlFromFile/WSDL/SnapshotPull.wsdl +++ b/src/SoapCore.Tests/WsdlFromFile/WSDL/SnapshotPull.wsdl @@ -6,16 +6,17 @@ This wsdl document is the reference with which each DATEX II Web Service has to be built Refer http://datex2.eu - + + - + @@ -23,7 +24,7 @@ - + @@ -31,7 +32,7 @@ - + @@ -44,7 +45,7 @@ - + The service endpoint diff --git a/src/SoapCore.Tests/WsdlFromFile/WsdlIncludeTests.cs b/src/SoapCore.Tests/WsdlFromFile/WsdlIncludeTests.cs index d5323299..293c8234 100644 --- a/src/SoapCore.Tests/WsdlFromFile/WsdlIncludeTests.cs +++ b/src/SoapCore.Tests/WsdlFromFile/WsdlIncludeTests.cs @@ -41,7 +41,7 @@ public void CheckWsdlInclude() var addresses = _host.ServerFeatures.Get(); var address = addresses.Addresses.Single(); - string url = address + "/Management/Service2.asmx?import&name=ServiceDefinitions.xml"; + string url = address + "/Management/Service2.asmx?import&name=ServiceDefinitions.xml"; Assert.IsNotNull(element); Assert.AreEqual(url, element.Attributes["location"]?.Value); @@ -67,7 +67,7 @@ public void CheckXSDInclude() var addresses = _host.ServerFeatures.Get(); var address = addresses.Addresses.Single(); - string url = address + "/Management/Service.asmx?xsd&name=echoInclude.xsd"; + string url = address + "/Management/Service.asmx?xsd&name=echoInclude.xsd"; Assert.IsNotNull(element); Assert.AreEqual(url, element.Attributes["schemaLocation"]?.Value); @@ -110,7 +110,7 @@ public void CheckXSDIncludeXSD() var addresses = _host.ServerFeatures.Get(); var address = addresses.Addresses.Single(); - string url = address + "/Service.asmx?xsd&name=echoIncluded.xsd"; + string url = address + "/Service.asmx?xsd&name=echoIncluded.xsd"; Assert.IsNotNull(element); Assert.AreEqual(url, element.Attributes["schemaLocation"]?.Value); diff --git a/src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs b/src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs index 6b2f65ba..3be95ab6 100644 --- a/src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs +++ b/src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs @@ -96,15 +96,19 @@ public void CheckXSDImport() nsmgr.AddNamespace("soapbind", "http://schemas.xmlsoap.org/wsdl/soap/"); var element = root.SelectSingleNode("/wsdl:definitions/wsdl:types/xs:schema/xs:import[1]", nsmgr); + var importWithoutSchemaLocation = root.SelectSingleNode("/wsdl:definitions/wsdl:types/xs:schema/xs:import[3]", nsmgr); var addresses = _host.ServerFeatures.Get(); var address = addresses.Addresses.Single(); - string url = address + "/Management/Service.asmx?xsd&name=DATEXII_3_MessageContainer.xsd"; + string url = address + "/Management/Service.asmx?xsd&name=DATEXII_3_MessageContainer.xsd"; Assert.IsNotNull(element); Assert.AreEqual(element.Attributes["namespace"]?.Value, "http://datex2.eu/schema/3/messageContainer"); Assert.AreEqual(element.Attributes["schemaLocation"]?.Value, url); + Assert.IsNotNull(importWithoutSchemaLocation); + Assert.IsNull(importWithoutSchemaLocation.Attributes["schemaLocation"]?.Value); + Assert.AreEqual(importWithoutSchemaLocation.Attributes["namespace"]?.Value, "http://datex2.eu/schema/3/commonExtension"); } [TestCleanup] diff --git a/src/SoapCore/Meta/MetaFromFile.cs b/src/SoapCore/Meta/MetaFromFile.cs index b70fc94a..c379162c 100644 --- a/src/SoapCore/Meta/MetaFromFile.cs +++ b/src/SoapCore/Meta/MetaFromFile.cs @@ -82,9 +82,9 @@ private XmlAttribute EnsureAttribute(XmlDocument xmlDoc, XmlNode node, string at public string ModifyWSDLAddRightSchemaPath(string xmlString) { - var xmlDoc = new XmlDocument() { XmlResolver = null }; + var xmlDoc = new XmlDocument() { XmlResolver = null }; var sr = new StringReader(xmlString); - var reader = XmlReader.Create(sr, new XmlReaderSettings() { XmlResolver = null }); + var reader = XmlReader.Create(sr, new XmlReaderSettings() { XmlResolver = null }); xmlDoc.Load(reader); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) @@ -93,7 +93,7 @@ public string ModifyWSDLAddRightSchemaPath(string xmlString) { var attribute = EnsureAttribute(xmlDoc, node, "location"); string name = attribute.InnerText.Replace("./", string.Empty); - attribute.InnerText = WebServiceLocation() + "?import&name=" + name; + attribute.InnerText = WebServiceLocation() + "?import&name=" + name; } if (XsdFolder != null && node.Prefix == xmlDoc.DocumentElement.Prefix && node.LocalName == "types") @@ -104,11 +104,12 @@ public string ModifyWSDLAddRightSchemaPath(string xmlString) { foreach (XmlNode importOrIncludeNode in schemaNode.ChildNodes) { - if (importOrIncludeNode.LocalName == "import" || importOrIncludeNode.LocalName == "include") + if ((importOrIncludeNode.LocalName == "import" && importOrIncludeNode.Attributes["schemaLocation"] != null) + || importOrIncludeNode.LocalName == "include") { var attribute = EnsureAttribute(xmlDoc, importOrIncludeNode, "schemaLocation"); string name = attribute.InnerText.Replace("./", string.Empty); - attribute.InnerText = SchemaLocation() + "&name=" + name; + attribute.InnerText = SchemaLocation() + "&name=" + name; } } } @@ -123,12 +124,12 @@ public string ModifyWSDLAddRightSchemaPath(string xmlString) { foreach (XmlNode portNode in schemaNode.ChildNodes) { - if (portNode.LocalName == "address") - { - var attribute = EnsureAttribute(xmlDoc, portNode, "location"); - attribute.InnerText = WebServiceLocation(); - break; - } + if (portNode.LocalName == "address") + { + var attribute = EnsureAttribute(xmlDoc, portNode, "location"); + attribute.InnerText = WebServiceLocation(); + break; + } } } } @@ -139,7 +140,7 @@ public string ModifyWSDLAddRightSchemaPath(string xmlString) } public string ModifyXSDAddRightSchemaPath(string xmlString) - { + { var xmlDoc = new XmlDocument() { XmlResolver = null }; var sr = new StringReader(xmlString); var reader = XmlReader.Create(sr, new XmlReaderSettings() { XmlResolver = null }); @@ -147,11 +148,12 @@ public string ModifyXSDAddRightSchemaPath(string xmlString) foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { - if (node.LocalName == "import" || node.LocalName == "include") + if ((node.LocalName == "import" && node.Attributes["schemaLocation"] != null) + || node.LocalName == "include") { var attribute = EnsureAttribute(xmlDoc, node, "schemaLocation"); string name = attribute.InnerText.Replace("./", string.Empty); - attribute.InnerText = SchemaLocation() + "&name=" + name; + attribute.InnerText = SchemaLocation() + "&name=" + name; } }