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

Wsdl schema mapping improvements #904

Merged
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
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,38 @@ To use it, add a setting like this to appsettings
```csharp
"FileWSDL": {
"UrlOverride": "",
"VirtualPath": "",
"WebServiceWSDLMapping": {
"Service.asmx": {
"Service.asmx": { ,
"UrlOverride": "Management/Service.asmx",
"WsdlFile": "snapshotpull.wsdl",
"SchemaFolder": "Schemas",
"WsdlFolder": "Schemas"
}
},
"VirtualPath": ""
}
```

* UrlOverride - can be used to override the URL in the service description. This can be useful if you are behind a firewall.
* Service.asmx - is the endpoint of the service you expose. You can have more than one.
* WsdlFile - is the name of the WSDL on disc.
* SchemaFolder - if you import XSD from WSDL, this is the folder where the Schemas are stored on disc.
* WsdlFolder - is the folder that the WSDL file is stored on disc.
* VirualPath - can be used if you like to add a path between the base URL and service.
* VirualPath - can be used if you like to add a path between the base URL and service.
* WebServiceWSDLMapping
* UrlOverride - can be used to override the URL for a specific WSDL mapping. This can be useful if you want to host different services under different folder.
* Service.asmx - is the endpoint of the service you expose. You can have more than one.
* WsdlFile - is the name of the WSDL on disc.
* SchemaFolder - if you import XSD from WSDL, this is the folder where the Schemas are stored on disc.
* WsdlFolder - is the folder that the WSDL file is stored on disc.


To read the setting you can do the following

In Startup.cs:


```csharp

var settings = Configuration.GetSection("FileWSDL").Get<WsdlFileOptions>();

// For case-insensitive mapping, if you are using "SoapCoreOptions.CaseInsensitivePath = true" - otherwise URLs with different casing won't be mapped correctly
//var settings = Configuration.GetSection("FileWSDL").Get<WsdlFileOptionsCaseInsensitive>();

settings.AppPath = env.ContentRootPath; // The hosting environment root path
...

Expand Down
6 changes: 4 additions & 2 deletions src/SoapCore.Tests/WsdlFromFile/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
{
SchemaFolder = "/WsdlFromFile/WSDL",
WsdlFile = _wsdlFile,
WSDLFolder = "/WsdlFromFile/WSDL"
WSDLFolder = "/WsdlFromFile/WSDL",
UrlOverride = "Management/Service.asmx"
}
}
},
Expand All @@ -69,7 +70,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
{
SchemaFolder = "/WsdlFromFile/WSDL",
WsdlFile = _wsdlFile,
WSDLFolder = "/WsdlFromFile/WSDL"
WSDLFolder = "/WsdlFromFile/WSDL",
UrlOverride = "Management/Service.asmx"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/SoapCore.Tests/WsdlFromFile/WsdlIncludeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void CheckXSDInclude()
var addresses = _host.ServerFeatures.Get<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/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);
Expand Down
4 changes: 2 additions & 2 deletions src/SoapCore.Tests/WsdlFromFile/WsdlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void CheckAddressLocation()
var addresses = _host.ServerFeatures.Get<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/Service.asmx";
string url = address + "/Management/Service.asmx";
Assert.IsNotNull(element);
Assert.AreEqual(element.Attributes["location"]?.Value, url);
}
Expand All @@ -100,7 +100,7 @@ public void CheckXSDImport()
var addresses = _host.ServerFeatures.Get<IServerAddressesFeature>();
var address = addresses.Addresses.Single();

string url = address + "/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");
Expand Down
16 changes: 13 additions & 3 deletions src/SoapCore/SoapEndpointMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -957,14 +957,24 @@ private async Task ProcessXSD(HttpContext httpContext)
private async Task ProcessMetaFromFile(HttpContext httpContext, bool showDocumentation)
{
var meta = new MetaFromFile();

var url = httpContext.Request.Path.Value.Replace("/", string.Empty);

WebServiceWSDLMapping mapping = _options.WsdlFileOptions.WebServiceWSDLMapping[url];

if (!string.IsNullOrEmpty(_options.WsdlFileOptions.VirtualPath))
{
meta.CurrentWebServer = _options.WsdlFileOptions.VirtualPath + "/";
}

meta.CurrentWebService = httpContext.Request.Path.Value.Replace("/", string.Empty);

WebServiceWSDLMapping mapping = _options.WsdlFileOptions.WebServiceWSDLMapping[meta.CurrentWebService];
if (string.IsNullOrEmpty(mapping.UrlOverride))
{
meta.CurrentWebService = url;
}
else
{
meta.CurrentWebService = mapping.UrlOverride;
}

meta.XsdFolder = mapping.SchemaFolder;
meta.WSDLFolder = mapping.WSDLFolder;
Expand Down
9 changes: 7 additions & 2 deletions src/SoapCore/WSDLFileOptions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System;
using System.Collections.Generic;
using SoapCore.Meta;

namespace SoapCore
{
public class WsdlFileOptions
{
public Dictionary<string, WebServiceWSDLMapping> WebServiceWSDLMapping { get; set; }
public virtual Dictionary<string, WebServiceWSDLMapping> WebServiceWSDLMapping { get; set; } = new Dictionary<string, WebServiceWSDLMapping>();
public string UrlOverride { get; set; }
public string VirtualPath { get; set; }
public string AppPath { get; set; }
}

public class WsdlFileOptionsCaseInsensitive : WsdlFileOptions
{
public override Dictionary<string, WebServiceWSDLMapping> WebServiceWSDLMapping { get; set; } = new Dictionary<string, WebServiceWSDLMapping>(StringComparer.OrdinalIgnoreCase);
}
}
13 changes: 7 additions & 6 deletions src/SoapCore/WebServiceWSDLMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace SoapCore
{
public class WebServiceWSDLMapping
{
public string WsdlFile { get; set; }
public string WSDLFolder { get; set; }
public string SchemaFolder { get; set; }
}
public class WebServiceWSDLMapping
{
public string UrlOverride { get; set; }
public string WsdlFile { get; set; }
public string WSDLFolder { get; set; }
public string SchemaFolder { get; set; }
}
}