AlexProutorov
AlexProutorov

Reputation: 707

How to inject WCF client into ServiceCollection with passing endpoint and credentials as parameters?

Currently we are moving away from Castle Windsor container and I've been struggling to find examples of how to inject WCF client into service collection in .NET Core Startup.cs. Does anybody know how to do that with passing endpoint and credentials?

Here is how it was done for Castle Windsor container:

container.Register(Component.For<IUserServiceV1>()
            .AsWcfClient(new DefaultClientModel
            {
                Endpoint = WcfEndpoint.BoundTo(new BasicHttpsBinding(BasicHttpsSecurityMode.TransportWithMessageCredential) { MaxReceivedMessageSize = 2147483647, ReceiveTimeout = new TimeSpan(0, 0, 5, 0), CloseTimeout = new TimeSpan(0, 0, 5, 0), OpenTimeout = new TimeSpan(0, 0, 5, 0), SendTimeout = new TimeSpan(0, 0, 5, 0) })
                        .At($"{userService.Url}/Services/UserService.svc")
            }
                .Credentials(new Castle.Facilities.WcfIntegration.Behaviors.UserNameCredentials(userService.Username, userService.Password)))
            .LifestyleTransient());

I would like to do that using .NET Core Microsoft.Extensions.DependencyInjection.

Upvotes: 2

Views: 993

Answers (1)

Abraham Qian
Abraham Qian

Reputation: 7522

From the code snippets, the WCF service on the server-side is created by BasichttpsBinding with TransportWithMessageCredential security mode and authenticates the client with username/password.
As far as I know, it is not compatible with the Asp.net Core project. Namely, it cannot be consumed properly in the Asp.net Core project. so it is not feasible.
enter image description here
Official repository.
https://github.com/dotnet/wcf/issues/8
I would like to know more details about the service on the server-side.
Feel free to let me know if there is anything I can help with.

Upvotes: 2

Related Questions