Пример #1
0
        static void Main(string[] args)
        {
            ChannelFactory <IAccess> channel = null;

            //
            // NOTE: Replace the string below with Address.ServiceAddress2 to utilize AccessService2.
            //
            string serviceAddressUsed = Address.ServiceAddress1;

            try
            {
                channel = new ChannelFactory <IAccess>(GetClientBinding(),
                                                       new EndpointAddress(new Uri(serviceAddressUsed),
                                                                           EndpointIdentity.CreateDnsIdentity("localhost")));
                IAccess client = channel.CreateChannel();
                (( IClientChannel )client).OperationTimeout = TimeSpan.MaxValue;

                Console.WriteLine("The client has started and is accessing the service hosted at address {0}.\n", serviceAddressUsed);
                client.Access(Address.PrintServiceAddress);

                Console.WriteLine("Press [Enter] to stop.\n");
                Console.ReadLine();
            }
            catch (MessageSecurityException)
            {
                Console.WriteLine("Message security exception. Possibly the STS issued an invalid UPN claim.");
                Console.WriteLine("Press [Enter] to stop.\n");
                Console.ReadLine();
            }
            finally
            {
                try
                {
                    if (channel != null)
                    {
                        channel.Close();
                    }
                }
                catch (CommunicationException)
                {
                }
                catch (TimeoutException)
                {
                }
            }
        }