CoreWCF / samples

MIT License
38 stars 19 forks source link

The sample throws an exception after upgrading all CoreWCF packages to the latest versions. #43

Closed thuannguy closed 1 year ago

thuannguy commented 1 year ago

Which sample is the bug for I use the NetCoreServer sample.

Describe the bug The sample throws an exception after upgrading all CoreWCF packages to the latest versions.

To Reproduce Steps to reproduce the behavior:

  1. Get clean code from GitHub
  2. Upgrade all CoreWCF packages to the latest version
image
  1. Run the sample
  2. Error: image

Error message: System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider' while attempting to activate 'Microsoft.AspNetCore.Authentication.AuthenticationMiddleware'.'

Stack trace:

   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) in /_1/microsoft.extensions.activatorutilities.sources/3.1.23-servicing.22123.2/contentFiles/cs/netstandard1.0/ActivatorUtilities.cs:line 391
   at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) in /_1/microsoft.extensions.activatorutilities.sources/3.1.23-servicing.22123.2/contentFiles/cs/netstandard1.0/ActivatorUtilities.cs:line 90
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next) in /_/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs:line 92
   at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build() in /_/src/Http/Http/src/Builder/ApplicationBuilder.cs:line 103
   at Microsoft.AspNetCore.Builder.MapWhenExtensions.MapWhen(IApplicationBuilder app, Func`2 predicate, Action`1 configuration) in /_/src/Http/Http.Abstractions/src/Extensions/MapWhenExtensions.cs:line 45
   at CoreWCF.Channels.ServiceModelHttpMiddleware.BuildBranch() in /_/src/CoreWCF.Http/src/CoreWCF/Channels/ServiceModelHttpMiddleware.cs:line 170
   at CoreWCF.Channels.ServiceModelHttpMiddleware.EnsureBranchBuilt() in /_/src/CoreWCF.Http/src/CoreWCF/Channels/ServiceModelHttpMiddleware.cs:line 64
   at CoreWCF.Channels.ServiceModelHttpMiddleware.ServiceBuilderOpenedCallback(Object sender, EventArgs e) in /_/src/CoreWCF.Http/src/CoreWCF/Channels/ServiceModelHttpMiddleware.cs:line 73
   at CoreWCF.Channels.CommunicationObject.OnOpened() in /_/src/CoreWCF.Primitives/src/CoreWCF/Channels/CommunicationObject.cs:line 503
--- End of stack trace from previous location ---
   at CoreWCF.Configuration.WrappingIServer.<StartAsync>d__9`1.MoveNext() in /_/src/CoreWCF.Primitives/src/CoreWCF/Configuration/WrappingIServer.cs:line 45
   at Microsoft.AspNetCore.Hosting.WebHost.<StartAsync>d__27.MoveNext() in /_/src/Hosting/Hosting/src/Internal/WebHost.cs:line 160
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.<RunAsync>d__5.MoveNext() in /_/src/Hosting/Hosting/src/WebHostExtensions.cs:line 111
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.<RunAsync>d__5.MoveNext() in /_/src/Hosting/Hosting/src/WebHostExtensions.cs:line 145
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.<RunAsync>d__4.MoveNext() in /_/src/Hosting/Hosting/src/WebHostExtensions.cs:line 95
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host) in /_/src/Hosting/Hosting/src/WebHostExtensions.cs:line 69
   at NetCoreServer.Program.Main(String[] args) in D:\code\CoreWCF-samples\Scenarios\Getting-Started-with-CoreWCF\NetCoreServer\Program.cs:line 15

Expected behavior The sample should work with the latest CoreWCF versions, or could anyone please give me some ideas about how to get it work? I can then contribute a PR to fix the sample.

Repo environment:

thuannguy commented 1 year ago

Well, the workaround that I found is changing from:

            .AddServiceEndpoint<HelloWorld, IHelloWorld>(new WSHttpBinding(SecurityMode.Transport), "/wsHttp");

To

     var myWSHttpBinding = new WSHttpBinding(SecurityMode.Transport);
     myWSHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; // this line is the key
...
     .AddServiceEndpoint<HelloWorld, IHelloWorld>(myWSHttpBinding, "/wsHttp");