Skip to content

Commit

Permalink
Merge pull request #897 from DigDes/develop
Browse files Browse the repository at this point in the history
v1.1.0.31
  • Loading branch information
kotovaleksandr authored Aug 29, 2022
2 parents 5e7979e + 077bd59 commit 3e0809d
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
<DefineConstants Condition="$(TargetFramework) == 'netcoreapp3.1'">$(DefineConstants);NETCOREAPP2_1_OR_GREATER;NETCOREAPP3_0_OR_GREATER</DefineConstants>
</PropertyGroup>

<ItemGroup>
<!-- https://github.com/dotnet/reproducible-builds -->
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>

</Project>
11 changes: 9 additions & 2 deletions src/SoapCore.Tests/Model/ComplexInheritanceModelInputBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace SoapCore.Tests.Model
{
[KnownType(typeof(ComplexInheritanceModelInputA))]
[KnownType(typeof(ComplexInheritanceModelInputB))]
[KnownType(nameof(GetKnownTypes))]
[DataContract(Name = "ComplexInheritanceModelInputBase")]
public abstract class ComplexInheritanceModelInputBase
{
Expand All @@ -12,5 +13,11 @@ public abstract class ComplexInheritanceModelInputBase

[DataMember]
public abstract string Example { get; set; }

private static IEnumerable<Type> GetKnownTypes()
{
yield return typeof(ComplexInheritanceModelInputA);
yield return typeof(ComplexInheritanceModelInputB);
}
}
}
21 changes: 21 additions & 0 deletions src/SoapCore.Tests/Wsdl/WsdlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,27 @@ public async Task CheckMessageHeadersServiceWsdl()
Assert.IsNotNull(stringPropertyElement);
}

[TestMethod]
public async Task CheckDataContractKnownTypeAttributeServiceWsdl()
{
var wsdl = await GetWsdlFromMetaBodyWriter<TestService>(SoapSerializer.DataContractSerializer);
Trace.TraceInformation(wsdl);
Assert.IsNotNull(wsdl);

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

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

var schemaElement = root.XPathSelectElement("//xsd:schema[@targetNamespace='http://schemas.datacontract.org/2004/07/SoapCore.Tests.Model']", nm);
Assert.IsNotNull(schemaElement);

Assert.IsNotNull(schemaElement.XPathSelectElement("//xsd:complexType[@name='ComplexInheritanceModelInputA']/xsd:complexContent/xsd:extension[@base='tns:ComplexInheritanceModelInputBase']", nm));
Assert.IsNotNull(schemaElement.XPathSelectElement("//xsd:element[@name='ComplexInheritanceModelInputA' and @type='tns:ComplexInheritanceModelInputA']", nm));
Assert.IsNotNull(schemaElement.XPathSelectElement("//xsd:complexType[@name='ComplexInheritanceModelInputB']/xsd:complexContent/xsd:extension[@base='tns:ComplexInheritanceModelInputA']", nm));
Assert.IsNotNull(schemaElement.XPathSelectElement("//xsd:element[@name='ComplexInheritanceModelInputB' and @type='tns:ComplexInheritanceModelInputB']", nm));
}

[TestCleanup]
public void StopServer()
{
Expand Down
5 changes: 5 additions & 0 deletions src/SoapCore/CustomMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
}
}

protected override void OnWriteStartHeaders(XmlDictionaryWriter writer)
{
writer.WriteStartElement(Version.Envelope.NamespacePrefix(NamespaceManager), "Header", Version.Envelope.Namespace());
}

protected override void OnWriteStartBody(XmlDictionaryWriter writer)
{
writer.WriteStartElement(Version.Envelope.NamespacePrefix(NamespaceManager), "Body", Version.Envelope.Namespace());
Expand Down
13 changes: 8 additions & 5 deletions src/SoapCore/Meta/MetaFromFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ public string ModifyWSDLAddRightSchemaPath(string xmlString)
{
if (importOrIncludeNode.Name == ImportNodeName(importOrIncludeNode) || importOrIncludeNode.Name == IncludeNodeName(importOrIncludeNode))
{
if (importOrIncludeNode.Attributes["schemaLocation"] == null)
if (XsdFolder != null)
{
importOrIncludeNode.Attributes.Append(xmlDoc.CreateAttribute("schemaLocation"));
}
if (importOrIncludeNode.Attributes["schemaLocation"] == null)
{
importOrIncludeNode.Attributes.Append(xmlDoc.CreateAttribute("schemaLocation"));
}

string name = importOrIncludeNode.Attributes["schemaLocation"].InnerText;
importOrIncludeNode.Attributes["schemaLocation"].InnerText = SchemaLocation() + "&name=" + name.Replace("./", string.Empty);
string name = importOrIncludeNode.Attributes["schemaLocation"].InnerText;
importOrIncludeNode.Attributes["schemaLocation"].InnerText = SchemaLocation() + "&name=" + name.Replace("./", string.Empty);
}
}
}
}
Expand Down
40 changes: 34 additions & 6 deletions src/SoapCore/Meta/MetaWCFBodyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,16 +713,44 @@ private void DiscoverTypes(Type type, bool isRootType)
IEnumerable<KnownTypeAttribute> knownTypes = type.GetCustomAttributes<KnownTypeAttribute>(inherit: false);
foreach (KnownTypeAttribute knownType in knownTypes)
{
if (knownType.Type is null)
if (knownType.Type is not null)
{
throw new NotSupportedException($"Only type property of `{nameof(KnownTypeAttribute)}` is supported.");
// add known type
_complexTypeToBuild[knownType.Type] = GetDataContractNamespace(knownType.Type);

// discover recursive
DiscoverTypes(knownType.Type, false);
}
else if (!string.IsNullOrWhiteSpace(knownType.MethodName))
{
var method = type.GetMethod(knownType.MethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (method is null)
{
throw new NotSupportedException($"Method `{knownType.MethodName}` doesn't exist on Type `{type.FullName}`.");
}

// add known type
_complexTypeToBuild[knownType.Type] = GetDataContractNamespace(knownType.Type);
var knownTypeList = method.Invoke(null, new object[0]) as IEnumerable;
if (knownTypeList is null)
{
throw new NotSupportedException($"Method `{knownType.MethodName}` on Type `{type.FullName}` returned null or not an IEnumerable.");
}

// discover recursive
DiscoverTypes(knownType.Type, false);
foreach (var item in knownTypeList.OfType<Type>())
{
if (item != null)
{
// add known type
_complexTypeToBuild[item] = GetDataContractNamespace(item);

// discover recursive
DiscoverTypes(item, false);
}
}
}
else
{
throw new NotSupportedException($"You must specify Type property or MethodName properties of `{nameof(KnownTypeAttribute)}`.");
}
}

if (HasBaseType(type) && type.BaseType != null)
Expand Down
2 changes: 1 addition & 1 deletion src/SoapCore/SoapCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>SOAP protocol middleware for ASP.NET Core</Description>
<Version>1.1.0.30</Version>
<Version>1.1.0.31</Version>
<Authors>Digital Design</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<PackageId>SoapCore</PackageId>
Expand Down
7 changes: 7 additions & 0 deletions src/SoapCore/SoapEndpointExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,12 @@ public static IServiceCollection AddSoapMessageProcessor(this IServiceCollection
serviceCollection.AddSingleton<ISoapMessageProcessor>(new LambdaSoapMessageProcessor(messageProcessor));
return serviceCollection;
}

public static IServiceCollection AddSoapMessageProcessor<TProcessor>(this IServiceCollection serviceCollection, ServiceLifetime lifetime = ServiceLifetime.Singleton)
where TProcessor : class, ISoapMessageProcessor
{
serviceCollection.Add(new ServiceDescriptor(typeof(ISoapMessageProcessor), typeof(TProcessor), lifetime));
return serviceCollection;
}
}
}

0 comments on commit 3e0809d

Please sign in to comment.