Ejemplo n.º 1
0
        /// <summary>
        /// Crea una solicitud al servidor para obtener los datos de un <c>Jugador</c>
        /// </summary>
        /// <param name="actualPlayer"></param>
        /// <exception>
        /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
        /// </exception>
        public static void GetActualPlayer(Jugador actualPlayer)
        {
            InstanceContext     instanceContext = new InstanceContext(new PlayerCallbackHandler());
            PlayerManagerClient server          = new PlayerManagerClient(instanceContext);

            try
            {
                server.GetActualPlayer(actualPlayer);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show("No se ha podido conectar a la Base de datos, intentar mas tarde");
            }
        }
Ejemplo n.º 2
0
        public void SendActualPlayer_ReturnErrorObtainingData_DataObtainedResult()
        {
            try
            {
                var baseAddress = new Uri("net.tcp://localhost:8090/Contratos");
                serviceHost = new ServiceHost(typeof(Contratos.MainService), baseAddress);
                System.ServiceModel.Channels.Binding binding = new NetTcpBinding();
                var address  = new EndpointAddress("net.tcp://localhost:8090/ServerTests");
                var endpoint = serviceHost
                               .AddServiceEndpoint(typeof(Contratos.IPlayerManager), binding, address.Uri);

                var smb = new ServiceMetadataBehavior {
                    HttpGetEnabled = false
                };
                serviceHost.Description.Behaviors.Add(smb);
                InstanceContext instanceContext = new InstanceContext(new PlayerCallbackHandler());
                playerClient  = new PlayerManagerClient(instanceContext);
                endpoint.Name = playerClient.Endpoint.Name;

                serviceHost.Open();
                serviceHost.Close();

                Jugador testPlayer = new Jugador
                {
                    Apodo       = "savetestplayer",
                    Contrasenia = "password123",
                };

                playerClient.GetActualPlayer(testPlayer);
                PlayerCallbackHandler playerHandler = new PlayerCallbackHandler();
                DataObtainedResult    result        = playerHandler.dataObtainedResult;

                Assert.AreEqual(result, DataObtainedResult.ErrorObtainingData);
            }
            catch (EndpointNotFoundException)
            {
                playerClient.Abort();
            }
            catch (CommunicationException)
            {
                playerClient.Abort();
            }
        }