Skip to content

Commit

Permalink
Merge pull request #767 from DigDes/develop
Browse files Browse the repository at this point in the history
v1.1.0.22
  • Loading branch information
kotovaleksandr authored Dec 1, 2021
2 parents 522dc7b + bc18b25 commit 6e122e1
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 31 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ Support ref\out params, exceptions. Works with legacy SOAP\WCF-clients.

The following frameworks are supported:

- .NET 6.0 (using ASP.NET Core 6.0)
- .NET 5.0 (using ASP.NET Core 5.0)
- .NET Core 3.1 (using ASP.NET Core 3.1)
- .NET Core 2.1 (using ASP.NET Core 2.1)
- .NET Standard 2.1 (using ASP.NET Core 2.1)
- .NET Standard 2.0 (using ASP.NET Core 2.1)

### Installing
Expand Down
14 changes: 6 additions & 8 deletions src/SoapCore.Benchmark/SoapCore.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<CodeAnalysisRuleSet>..\SoapCore.ruleset</CodeAnalysisRuleSet>
<NoWin32Manifest>true</NoWin32Manifest>
<LangVersion>8</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework) =='netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
Expand All @@ -23,8 +17,12 @@
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net6.0'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/SoapCore.Benchmark/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;

namespace SoapCore.Benchmark
{
Expand All @@ -14,7 +16,7 @@ public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app)
{
app.UseSoapEndpoint<PingService>("/TestService.asmx", new SoapEncoderOptions(), SoapSerializer.DataContractSerializer);
app.Use(async (ctx, next) =>
app.Use(async (HttpContext ctx, Func<Task> next) =>
{
await ctx.Response.WriteAsync("").ConfigureAwait(false);
});
Expand Down
2 changes: 1 addition & 1 deletion src/SoapCore.Tests/Wsdl/WsdlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ private async Task<string> GetWsdlFromMetaBodyWriter<T>(SoapSerializer serialize
var bodyWriter = serializer == SoapSerializer.DataContractSerializer
? new MetaWCFBodyWriter(service, baseUrl, "BasicHttpBinding", false) as BodyWriter
: new MetaBodyWriter(service, baseUrl, xmlNamespaceManager, "BasicHttpBinding", new[] { MessageVersion.None }) as BodyWriter;
var encoder = new SoapMessageEncoder(MessageVersion.Soap12WSAddressingAugust2004, System.Text.Encoding.UTF8, XmlDictionaryReaderQuotas.Max, false, true);
var encoder = new SoapMessageEncoder(MessageVersion.Soap12WSAddressingAugust2004, System.Text.Encoding.UTF8, XmlDictionaryReaderQuotas.Max, false, true, false);
var responseMessage = Message.CreateMessage(encoder.MessageVersion, null, bodyWriter);
responseMessage = new MetaMessage(responseMessage, service, xmlNamespaceManager, "BasicHttpBinding", false);

Expand Down
10 changes: 7 additions & 3 deletions src/SoapCore/MessageEncoder/SoapMessageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public class SoapMessageEncoder
private readonly bool _omitXmlDeclaration;
private readonly bool _indentXml;
private readonly bool _supportXmlDictionaryReader;
private readonly bool _checkXmlCharacters;

public SoapMessageEncoder(MessageVersion version, Encoding writeEncoding, XmlDictionaryReaderQuotas quotas, bool omitXmlDeclaration, bool indentXml)
public SoapMessageEncoder(MessageVersion version, Encoding writeEncoding, XmlDictionaryReaderQuotas quotas, bool omitXmlDeclaration, bool indentXml, bool checkXmlCharacters)
{
_indentXml = indentXml;
_omitXmlDeclaration = omitXmlDeclaration;
_checkXmlCharacters = checkXmlCharacters;
if (writeEncoding == null)
{
throw new ArgumentNullException(nameof(writeEncoding));
Expand Down Expand Up @@ -153,7 +155,8 @@ public virtual async Task WriteMessageAsync(Message message, PipeWriter pipeWrit
OmitXmlDeclaration = _optimizeWriteForUtf8 && _omitXmlDeclaration, //can only omit if utf-8
Indent = _indentXml,
Encoding = _writeEncoding,
CloseOutput = true
CloseOutput = true,
CheckCharacters = _checkXmlCharacters
});

using var xmlWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlTextWriter);
Expand Down Expand Up @@ -183,7 +186,8 @@ public virtual Task WriteMessageAsync(Message message, Stream stream)
OmitXmlDeclaration = _optimizeWriteForUtf8 && _omitXmlDeclaration, //can only omit if utf-8,
Indent = _indentXml,
Encoding = _writeEncoding,
CloseOutput = false
CloseOutput = false,
CheckCharacters = _checkXmlCharacters
});

using var xmlWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlTextWriter);
Expand Down
13 changes: 2 additions & 11 deletions 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.21</Version>
<Version>1.1.0.22</Version>
<Authors>Digital Design</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<PackageId>SoapCore</PackageId>
Expand All @@ -27,7 +27,7 @@
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'netcoreapp2.1'">
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0" />
Expand All @@ -49,14 +49,6 @@
<PackageReference Include="System.CodeDom" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.IO.Pipelines" Version="6.0.0" />
<PackageReference Include="System.CodeDom" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\logo.png">
<Pack>True</Pack>
Expand All @@ -65,7 +57,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.ServiceModel.Primitives" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 6 additions & 0 deletions src/SoapCore/SoapCoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class SoapCoreOptions
/// </summary>
public bool IndentXml { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether to check to make sure that the XmlOutput doesn't contain invalid characters
/// <para>Defaults to true</para>
/// </summary>
public bool CheckXmlCharacters { get; set; } = true;

/// <summary>
/// Gets or sets an collection of Xml Namespaces to override the default prefix for.
/// </summary>
Expand Down
11 changes: 7 additions & 4 deletions src/SoapCore/SoapEndpointMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SoapEndpointMiddleware(ILogger<SoapEndpointMiddleware<T_MESSAGE>> logger,

for (var i = 0; i < options.EncoderOptions.Length; i++)
{
_messageEncoders[i] = new SoapMessageEncoder(options.EncoderOptions[i].MessageVersion, options.EncoderOptions[i].WriteEncoding, options.EncoderOptions[i].ReaderQuotas, options.OmitXmlDeclaration, options.IndentXml);
_messageEncoders[i] = new SoapMessageEncoder(options.EncoderOptions[i].MessageVersion, options.EncoderOptions[i].WriteEncoding, options.EncoderOptions[i].ReaderQuotas, options.OmitXmlDeclaration, options.IndentXml, options.CheckXmlCharacters);
}
}

Expand Down Expand Up @@ -686,9 +686,12 @@ private async Task<Message> WriteErrorResponseMessage(
var faultExceptionTransformer = serviceProvider.GetRequiredService<IFaultExceptionTransformer>();
var faultMessage = faultExceptionTransformer.ProvideFault(exception, messageEncoder.MessageVersion, requestMessage, xmlNamespaceManager);

httpContext.Response.ContentType = httpContext.Request.ContentType;
httpContext.Response.Headers["SOAPAction"] = faultMessage.Headers.Action;
httpContext.Response.StatusCode = statusCode;
if(!httpContext.Response.HasStarted)
{
httpContext.Response.ContentType = httpContext.Request.ContentType;
httpContext.Response.Headers["SOAPAction"] = faultMessage.Headers.Action;
httpContext.Response.StatusCode = statusCode;
}

SetHttpResponse(httpContext, faultMessage);
if (messageEncoder.MessageVersion.Addressing == AddressingVersion.WSAddressing10)
Expand Down
9 changes: 8 additions & 1 deletion src/SoapCore/SoapOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public class SoapOptions

public bool IndentXml { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether to check to make sure that the XmlOutput doesn't contain invalid characters
/// <para>Defaults to true</para>
/// </summary>
public bool CheckXmlCharacters { get; set; } = true;

public XmlNamespaceManager XmlNamespacePrefixOverrides { get; set; }
public WsdlFileOptions WsdlFileOptions { get; set; }

Expand All @@ -66,7 +72,8 @@ public static SoapOptions FromSoapCoreOptions(SoapCoreOptions opt, Type serviceT
OmitXmlDeclaration = opt.OmitXmlDeclaration,
IndentXml = opt.IndentXml,
XmlNamespacePrefixOverrides = opt.XmlNamespacePrefixOverrides,
WsdlFileOptions = opt.WsdlFileOptions
WsdlFileOptions = opt.WsdlFileOptions,
CheckXmlCharacters = opt.CheckXmlCharacters
};

#pragma warning disable CS0612 // Type or member is obsolete
Expand Down
2 changes: 1 addition & 1 deletion src/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.100",
"version": "6.0.100",
"rollForward": "latestMajor"
}
}

0 comments on commit 6e122e1

Please sign in to comment.