Using Windsor Castle and WcfFacility to create a WCF proxy with Message Security and username authority

OK, we use message security with user credentials (and X509 certificate encryption) to communicate with our WCF service. I am not happy with this approach, but this is not a question, and I do not want to delve into it.

I use Windsor Castle to create proxies in ASP NET Web Forms + MVC hybrid . We use form authentication and use user credentials to communicate with WCF services - this will help audit all calls. As I said, I am not happy with this approach, but this is not the point.

I created a class CustomCredentialsthat inherits from the class AbstractCredentials, and WcfFacility happily uses it to configure my proxies. As you will see below, all my settings are just a few lines. I created a unit test below, which demonstrates everything I do: create a proxy, call, and then release it in a loop. Now I expect this test to work, but it is not, and I get

Expected: 10 But was: 1

I did not enable the binding, but that doesn’t matter since I said that I use Message Security with X509 certificates.

I know that for a factory channel with message protection after opening you cannot change credentials. Is this the same problem?

Is this a bug in WcfFacility or a limitation?

Here is the code

[TestFixture]
public class Harness
{

    private IWindsorContainer _container;
    public static int NumberOfTimesCredentialsConfigured = 0;

    [SetUp]
    public void Setup()
    {
        _container = new WindsorContainer().AddFacility<WcfFacility>();

    Component
        .For<IFrameworkUsers>()
        .ActAs(DefaultClientModel
        .On(WcfEndpoint.FromConfiguration("FrameworkUsersService"))
        .Credentials(new CustomCredentials()))
        .LifeStyle.Transient);
    }

    [Test]
    public void MultipleProxyTest()
    {

        const int Runs = 10;
        NumberOfTimesCredentialsConfigured = 0;
        for (int i = 0; i < Runs; i++)
        {
            IFrameworkUsers frameworkUsers = _container.Resolve<IFrameworkUsers>();
            frameworkUsers.CreateUserSession();
            _container.Release(frameworkUsers);
        }

        Assert.AreEqual(Runs, NumberOfTimesCredentialsConfigured);
                    // FAILS!!! Expected: 10  But was:  1
    }

    [TearDown]
    public void TearDown()
    {

    }


}

public class CustomCredentials : AbstractCredentials
{


    #region Overrides of AbstractCredentials

    protected override void ConfigureCredentials(ClientCredentials credentials)
    {
        credentials.UserName.UserName = "testuser";
        credentials.UserName.Password = "abcdef";

        Harness.NumberOfTimesCredentialsConfigured++;
    }

    #endregion
} 
+3
source share
2 answers

. WCF Facility, , , , .

+1

IWcfEndpoint ( DefaultClientModel.On(...)) , . - , :

_container.Register(Component.For<IFrameworkUsers>()
    .AsWcfClient()
    .DependsOn(
        (k, d) => d["endpoint"] = 
            new DefaultClientModel(WcfEndpoint.FromConfiguration("FrameworkUsersService"))
                .Credentials(new CustomCredentials())
     )
    .LifeStyle.Transient);

String endpoint , WcfFacility. , , - ( , ). , AsWcfClient(IWcfEndpoint endpoint).

, , , WcfFacility.

0

Source: https://habr.com/ru/post/1792183/


All Articles