示例#1
0
    public static void ClientBaseChannelFactoryAlwaysOnCachingBindingEndpointAddress()
    {
        MyClientBase2.CacheSetting = CacheSetting.AlwaysOn;
        BasicHttpBinding binding         = new BasicHttpBinding();
        EndpointAddress  endpointAddress = new EndpointAddress("http://myendpoint");
        MyClientBase2    client1         = new MyClientBase2(binding, endpointAddress);

        client1.Open();
        MyClientBase2 client2 = new MyClientBase2(binding, endpointAddress);

        client2.Open();
        // Validate using the same ChannelFactory when constructor args are the same
        Assert.Equal(client1.ChannelFactory, client2.ChannelFactory);
        MyClientBase2 client3 = new MyClientBase2(binding, new EndpointAddress("http://myendpoint"));

        client3.Open();
        // Validate using the same ChannelFactory when constructor args are equivalent
        Assert.Equal(client1.ChannelFactory, client3.ChannelFactory);
        MyClientBase2 client4 = new MyClientBase2(binding, new EndpointAddress("http://myotherendpoint"));

        // Validate using different ChannelFactory when constructor args are not equivalent
        Assert.NotEqual(client1.ChannelFactory, client4.ChannelFactory);
        client1.Close();
        client2.Close();
        client3.Close();
        client4.Close();
        // Validate setting to same value doesn't throw
        MyClientBase2.CacheSetting = CacheSetting.AlwaysOn;
        // Validate instantiated caching throws when changing setting
        Assert.Throws <InvalidOperationException>(() => MyClientBase2.CacheSetting = CacheSetting.Default);
    }
示例#2
0
    public static void ClientBaseChannelFactoryAlwaysOnServiceEndpoint()
    {
        MyClientBase2.CacheSetting = CacheSetting.AlwaysOn;
        BasicHttpBinding binding                   = new BasicHttpBinding();
        EndpointAddress  endpointAddress           = new EndpointAddress("http://myendpoint");
        ChannelFactory <ITestService2> tempFactory = new ChannelFactory <ITestService2>(binding, endpointAddress);
        ServiceEndpoint serviceEndpoint            = tempFactory.Endpoint;
        MyClientBase2   client1 = new MyClientBase2(serviceEndpoint);

        client1.Open();
        MyClientBase2 client2 = new MyClientBase2(serviceEndpoint);

        client2.Open();
        // Validate using the same ChannelFactory when constructor args are the same
        Assert.Equal(client1.ChannelFactory, client2.ChannelFactory);
        tempFactory = new ChannelFactory <ITestService2>(binding, endpointAddress);
        ServiceEndpoint serviceEndpoint2 = tempFactory.Endpoint;
        MyClientBase2   client3          = new MyClientBase2(serviceEndpoint2);

        client3.Open();
        // Validate using different ChannelFactory when constructor args are not the same
        Assert.NotEqual(client1.ChannelFactory, client3.ChannelFactory);
        var existingChannelFactory = client1.ChannelFactory;

        client1.Close();
        client2.Close();
        client3.Close();
        // Validate that ChannelFactory is replaced if existing one is closed
        existingChannelFactory.Close();
        Assert.Equal(CommunicationState.Closed, existingChannelFactory.State);
        MyClientBase2 client4 = new MyClientBase2(serviceEndpoint);

        client4.Open();
        Assert.NotEqual(existingChannelFactory, client4.ChannelFactory);
        // Validate setting to same value doesn't throw
        MyClientBase2.CacheSetting = CacheSetting.AlwaysOn;
        // Validate instantiated caching throws when changing setting
        Assert.Throws <InvalidOperationException>(() => MyClientBase2.CacheSetting = CacheSetting.Default);
    }