Skip to content

Commit

Permalink
Merge pull request #920 from DigDes/develop
Browse files Browse the repository at this point in the history
v1.1.0.34
  • Loading branch information
kotovaleksandr authored Nov 7, 2022
2 parents 3e0809d + fdc5517 commit 42b3fdf
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 352 deletions.
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
49 changes: 49 additions & 0 deletions src/SoapCore.Tests/Wsdl/Services/DefaultValuesAttributesService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.ComponentModel;
using System.ServiceModel;

namespace SoapCore.Tests.Wsdl.Services
{
#pragma warning disable SA1649 // File name should match first type name
#pragma warning disable SA1402 // File may only contain a single type
[ServiceContract(Namespace = "http://bagov.net")]
public interface IDefaultValueAttributesService
{
[OperationContract]
DefaultValueAttributesResponseType GetResponse();
}

public class DefaultValueAttributesService : IDefaultValueAttributesService
{
public DefaultValueAttributesResponseType GetResponse()
{
return new DefaultValueAttributesResponseType();
}
}

public class DefaultValueAttributesResponseType
{
public bool BooleanWithNoDefaultProperty { get; set; }

[DefaultValue(null)]
public bool BooleanWithDefaultNullProperty { get; set; }

[DefaultValue(false)]
public bool BooleanWithDefaultFalseProperty { get; set; }

[DefaultValue(true)]
public string BooleanWithDefaultTrueProperty { get; set; }

public int IntWithNoDefaultProperty { get; set; }

[DefaultValue(42)]
public int IntWithDefaultProperty { get; set; }

public string StringWithNoDefaultProperty { get; set; }

[DefaultValue(null)]
public string StringWithDefaultNullProperty { get; set; }

[DefaultValue("default")]
public string StringWithDefaultProperty { get; set; }
}
}
40 changes: 40 additions & 0 deletions src/SoapCore.Tests/Wsdl/WsdlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,46 @@ public async Task CheckMessageHeadersServiceWsdl()
Assert.IsNotNull(stringPropertyElement);
}

[TestMethod]
public async Task CheckDefaultValueAttributesServiceWsdl()
{
var wsdl = await GetWsdlFromMetaBodyWriter<DefaultValueAttributesService>(SoapSerializer.XmlSerializer);
Trace.TraceInformation(wsdl);
Assert.IsNotNull(wsdl);

Assert.IsFalse(wsdl.Contains("name=\"\""));

var root = XElement.Parse(wsdl);
var nm = Namespaces.CreateDefaultXmlNamespaceManager();

var booleanWithNoDefaultPropertyElement = root.XPathSelectElement("//xsd:element[@name='BooleanWithNoDefaultProperty' and @minOccurs='1' and @maxOccurs='1' and not(@default)]", nm);
Assert.IsNotNull(booleanWithNoDefaultPropertyElement);

var booleanWithDefaultNullPropertyElement = root.XPathSelectElement("//xsd:element[@name='BooleanWithDefaultNullProperty' and @minOccurs='1' and @maxOccurs='1' and not(@default)]", nm);
Assert.IsNotNull(booleanWithDefaultNullPropertyElement);

var booleanWithDefaultFalsePropertyElement = root.XPathSelectElement("//xsd:element[@name='BooleanWithDefaultFalseProperty' and @minOccurs='0' and @maxOccurs='1' and @default='false']", nm);
Assert.IsNotNull(booleanWithDefaultFalsePropertyElement);

var booleanWithDefaultTruePropertyElement = root.XPathSelectElement("//xsd:element[@name='BooleanWithDefaultTrueProperty' and @minOccurs='0' and @maxOccurs='1' and @default='true']", nm);
Assert.IsNotNull(booleanWithDefaultTruePropertyElement);

var intWithNoDefaultPropertyElement = root.XPathSelectElement("//xsd:element[@name='IntWithNoDefaultProperty' and @minOccurs='1' and @maxOccurs='1' and not(@default)]", nm);
Assert.IsNotNull(intWithNoDefaultPropertyElement);

var intWithDefaultPropertyElement = root.XPathSelectElement("//xsd:element[@name='IntWithDefaultProperty' and @minOccurs='0' and @maxOccurs='1' and @default='42']", nm);
Assert.IsNotNull(intWithDefaultPropertyElement);

var stringWithNoDefaultPropertyElement = root.XPathSelectElement("//xsd:element[@name='StringWithNoDefaultProperty' and @minOccurs='0' and @maxOccurs='1' and not(@default)]", nm);
Assert.IsNotNull(stringWithNoDefaultPropertyElement);

var stringWithDefaultNullPropertyElement = root.XPathSelectElement("//xsd:element[@name='StringWithDefaultNullProperty' and @minOccurs='0' and @maxOccurs='1' and not(@default)]", nm);
Assert.IsNotNull(stringWithDefaultNullPropertyElement);

var stringWithDefaultPropertyElement = root.XPathSelectElement("//xsd:element[@name='StringWithDefaultProperty' and @minOccurs='0' and @maxOccurs='1' and @default='default']", nm);
Assert.IsNotNull(stringWithDefaultPropertyElement);
}

[TestMethod]
public async Task CheckDataContractKnownTypeAttributeServiceWsdl()
{
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
Loading

0 comments on commit 42b3fdf

Please sign in to comment.