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

.NET8 IEndpointBehavior.ApplyDispatchBehavior can't access anything from passed EndpointDispatcher #5555

Closed
j-bernhard opened this issue May 28, 2024 · 4 comments
Assignees
Labels

Comments

@j-bernhard
Copy link

Hy,

Describe the bug

I am trying to migrate an existing project from .net48 to .net8. During migration an existing implementation of IEndpointBehavior I get stucked. Because the compiler does not found the property DispatchRuntime, but if I look into the implementation the property is already there (but returns always null, what is also confusing to me), see screenshot.

Also intellisense does not provide any property of the EndpointDispatcher, what I don't understand, because everything is public, see second screenshot.

Targetframework: .net8.0-windows
Packages:

  • System.ServiceModel.NetTcp (8.0.0)
  • System.ServiceModel.Primitives (8.0.0)

To Reproduce
Added a playground project, to abstract things from the main project... Important part is the .net8 client - HeaderContextBehavior, Line 49.
The idea is to add and retrieve custom header information from the messages.

(Currently the sample server does nothing with added header information. But during porting same things for the server part with core wcf , the DispatchRuntime property is available, as I see in my main project.)

CoreWcf.zip

Expected behavior
That the property can be access and provide the same behavior as before (net48), or another way how to solve issue.

Screenshots
image

image

Additional context

Regards,
Joerg

@mconnew
Copy link
Member

mconnew commented May 28, 2024

You can get to the DispatchRuntime in the ApplyClientBehavior method. Change your implementation to this and it should work. Let me know if that doesn't work for you.

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.ClientMessageInspectors.Add(new ClientHeaderContextHandler());
            clientRuntime.CallbackDispatchRuntime.MessageInspectors.Add(new ServiceHeaderContextHandler());
        }

@j-bernhard
Copy link
Author

@mconnew thx for the fast answer. I will check and let you know.

@HongGit
Copy link
Contributor

HongGit commented Jun 27, 2024

Close this issue assuming this is working for you. Feel free to re-activate if not.

@HongGit HongGit closed this as completed Jun 27, 2024
@omachacek
Copy link

omachacek commented Jun 28, 2024

@j-bernhard @mconnew
Hi,
I have a similar problem while trying to register EndpointBehaviors to SOAP endpoint in Program.cs. The method UseSoapEndpoint does not allow me to add EndpointBehaviors.
Do you have any advice or recommendations for me?

Thank you,
Ondřej Macháček

builder.Services.AddSingleton<ServerMessageLoggerBehavior>();

var app = builder.Build();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
    endpoints.UseSoapEndpoint<ISimpleSOAPService>("/SimpleSOAPService.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer, configure =>
    {
        var serviceProvider = app.Services;
        var logger = serviceProvider.GetRequiredService<ILogger<ServerMessageInspector>>();
        configure.EndpointBehaviors.Add(new ServerMessageLoggerBehavior(logger));
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants