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

[Bug]: IEndpointBehavior.AddBindingParameters not called when registered in AddServiceEndpoint's configureEndpoint method #1353

Open
1 task done
andradf opened this issue Mar 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@andradf
Copy link

andradf commented Mar 14, 2024

Duplicate ?

  • I have searched issues/discussions and did not find other issues/discussions reporting this bug.

Product version

1.5.1

Describe expected behavior

When adding an IEndpointBehavior to an endpoint, like in WCF, I would expect IEndpointBehavior's AddBindingParameters to be called before ApplyDispatchBehavior.

Describe actual behavior

In CoreWCF, the method AddBindingParameters is not called at all.

Looking through the code it looks to me like the source of the problem is that endpoint configuration is performed as part of EndpointConfiguratorEndpointBehavior's application. DispatcherBuilder.InitializeServiceHost calls AddBindingParameters only on the initial set of EndpointBehaviors (EndpointConfiguratorEndpointBehavior and EndpointAuthorizationBehavior), which doesn't include endpoints added in configureEndpoint. I'd imagine the solution should be to either not use a behavior to invoke the endpoint configuration, but rather call it right after creation or to move parameter binding to the same loop where behaviors are applied.

Which binding

NetTcp

security

None

Which .NET version

.NET 6

Which os platform

Windows

Code snippet used to reproduce the issue

app.UseServiceModel(builder =>
{
      var binding = new NetTcpBinding(CoreWCF.SecurityMode.None);
      builder.AddService<MyService>()
          .AddServiceEndpoint<MyService, IMyService>(binding, $"net.tcp://localhost:{net_tcp_port}/MyService/service", ep =>
      {
          ep.EndpointBehaviors.Add(new MyEndpointBehavior());
      })
});

Stacktrace if any

No response

@andradf andradf added the bug Something isn't working label Mar 14, 2024
@andradf
Copy link
Author

andradf commented Mar 15, 2024

For those who need a quick workaround in the meantime you can add the IEndPointBehavior in ConfigureServiceHostBase instead like this

...
builder.AddService<MyService>()
  .AddServiceEndpoint<MyService, IMyService>(binding, $"net.tcp://localhost:{net_tcp_port}/MyService/service")
  .ConfigureServiceHostBase<MyService>(serviceHost =>
  {
    serviceHost.Description.Endpoints.First(ep => ep.Contract.ContractType == typeof(IMyService)).EndpointBehaviors.Add(new MyEndpointBehavior());
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant