Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var client   = new SimpleServiceClient();
            var response = client.Authenticate(new AuthenticationRequest
            {
                Username = "******",
                Password = "******"
            });

            Console.WriteLine(response.Valid ? response.Message : "Error!");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var soapClient   = new SimpleServiceClient();
            var soapResponse = soapClient.GetData(4234);

            if (soapResponse != null)
            {
                Console.WriteLine(soapResponse);
            }

            var request = new AuthenticationRequest
            {
                Username = "******",
                Password = "******"
            };
            var soapResponse2 = soapClient.Authenticate(request);

            soapClient.Close();

            using (var restClient = new HttpClient
            {
                BaseAddress = new Uri("http://localhost:63852/SimpleService.svc/json/")
            })
            {
                var serilized    = JsonConvert.SerializeObject(request);
                var inputMessage = new HttpRequestMessage
                {
                    Content = new StringContent(serilized, Encoding.UTF8, "application/json")
                };
                inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var message = restClient.PutAsync("AuthReq", inputMessage.Content).Result;
                AuthorizationResponse restResponse = null;
                if (message.IsSuccessStatusCode)
                {
                    var inter = message.Content.ReadAsStringAsync();
                    restResponse = JsonConvert.DeserializeObject <AuthorizationResponse>(inter.Result);
                }

                if (restResponse != null)
                {
                    Console.WriteLine(restResponse.Message);
                }
            }

            Console.ReadKey();
        }