Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wsdl from file generation with import/include tags #1091

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
11 changes: 6 additions & 5 deletions src/SoapCore.Tests/WsdlFromFile/WSDL/SnapshotPull.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@
This wsdl document is the reference with which each DATEX II Web Service has to be built
Refer http://datex2.eu
</documentation>

<types>
<xs:schema targetNamespace="http://datex2.eu/wsdl/snapshotPull/2020">
<xs:import namespace="http://datex2.eu/schema/3/messageContainer" schemaLocation="./DATEXII_3_MessageContainer.xsd"/>
<xs:import namespace="http://datex2.eu/schema/3/exchangeInformation" schemaLocation="./DATEXII_3_ExchangeInformation.xsd"/>
<xs:import namespace="http://datex2.eu/schema/3/commonExtension"/>
<!-- Here, the "namespace" MUST be the same as the used DATEXII schema targetNamespace -->
<!-- Here, the "schemaLocation" depends on each implementation and MUST be filled by each developer, for instance "file:///C:/DATEXII/MessageContainer.xsd"-->
<!-- for snapshot pull no elelement definition for input message is needed
<xs:element name="pullSnapshotDataInput" type="ex:ExchangeInformation" /> -->
<xs:element name="pullSnapshotDataOutput" type="con:MessageContainer" />
<xs:element name="pullSnapshotDataOutput" type="con:MessageContainer" />
</xs:schema>
</types>

<message name="pullSnapshotDataInputMessage"/>
<message name="pullSnapshotDataOutputMessage">
<part name="return" element="tns:pullSnapshotDataOutput"/>
</message>

<portType name="snapshotPullInterface">
<operation name="pullSnapshotData">
<input message="tns:pullSnapshotDataInputMessage"/>
<!-- The SnapshotPull service doesn't use any input message but its declaration is here mandatory for a few Web Service frameworks-->
<output message="tns:pullSnapshotDataOutputMessage"/>
</operation>
</portType>

<binding name="snapshotPullSoapBinding" type="tns:snapshotPullInterface">
<soapbind:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="pullSnapshotData">
Expand All @@ -44,7 +45,7 @@
</output>
</operation>
</binding>

<service name="snapshotPull">
<port name="snapshotPullSoapEndPoint" binding="tns:snapshotPullSoapBinding">
<soapbind:documentation>The service endpoint</soapbind:documentation>
Expand Down
6 changes: 3 additions & 3 deletions src/SoapCore.Tests/WsdlFromFile/WsdlIncludeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void CheckWsdlInclude()
var addresses = _host.ServerFeatures.Get<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/Management/Service2.asmx?import&name=ServiceDefinitions.xml";
string url = address + "/Management/Service2.asmx?import&amp;name=ServiceDefinitions.xml";

Assert.IsNotNull(element);
Assert.AreEqual(url, element.Attributes["location"]?.Value);
Expand All @@ -67,7 +67,7 @@ public void CheckXSDInclude()
var addresses = _host.ServerFeatures.Get<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/Management/Service.asmx?xsd&name=echoInclude.xsd";
string url = address + "/Management/Service.asmx?xsd&amp;name=echoInclude.xsd";

Assert.IsNotNull(element);
Assert.AreEqual(url, element.Attributes["schemaLocation"]?.Value);
Expand Down Expand Up @@ -110,7 +110,7 @@ public void CheckXSDIncludeXSD()
var addresses = _host.ServerFeatures.Get<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/Service.asmx?xsd&name=echoIncluded.xsd";
string url = address + "/Service.asmx?xsd&amp;name=echoIncluded.xsd";

Assert.IsNotNull(element);
Assert.AreEqual(url, element.Attributes["schemaLocation"]?.Value);
Expand Down
6 changes: 5 additions & 1 deletion src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/Management/Service.asmx?xsd&name=DATEXII_3_MessageContainer.xsd";
string url = address + "/Management/Service.asmx?xsd&amp;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]
Expand Down
30 changes: 16 additions & 14 deletions src/SoapCore/Meta/MetaFromFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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&amp;name=" + name;
}

if (XsdFolder != null && node.Prefix == xmlDoc.DocumentElement.Prefix && node.LocalName == "types")
Expand All @@ -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() + "&amp;name=" + name;
}
}
}
Expand All @@ -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;
}
}
}
}
Expand All @@ -139,19 +140,20 @@ 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 });
xmlDoc.Load(reader);

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() + "&amp;name=" + name;
}
}

Expand Down
Loading