示例#1
0
        /// <summary>
        /// Http : DELETE
        /// </summary>
        public async Task DeletePerson()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    Console.WriteLine("OBTAINING people");
                    string getUrl = string.Format("http://localhost:8001/people");

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml,
                    //so we need to deserialize it as Xml
                    var response =
                        await client.Get <List <Person> >("http://localhost:8001/people", SerializationToUse.Xml);
                    Console.WriteLine("There are currently {0} people", response.Content.Count);

                    string deleteUrl = string.Format("http://localhost:8001/people/{0}", 1);

                    var statusCode = await client.Delete(deleteUrl);
                    Console.WriteLine("Http : DELETE");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(deleteUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING people again");
                        //the server PersonHandler [RouteBaseAttribute] is set to return Xml,
                        //so we need to deserialize it as Xml
                        response =
                            await client.Get <List <Person> >("http://localhost:8001/people", SerializationToUse.Xml);
                        Console.WriteLine("There are currently {0} people", response.Content.Count);
                    }
                    else
                    {
                        Console.WriteLine("DELETE Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#2
0
        public async Task DeleteUser()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    Console.WriteLine("OBTAINING users");
                    string getUrl = "http://localhost:8001/users/GetAllUsers";

                    //the server UserHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var response = await client.Get <List <User> >(getUrl, SerializationToUse.Json);
                    Console.WriteLine("There are currently {0} users", response.Content.Count);

                    string deleteUrl = string.Format("http://localhost:8001/users/DeleteUserByTheirId/{0}", 1);

                    var statusCode = await client.Delete(deleteUrl);
                    Console.WriteLine("Http : DELETE");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(deleteUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING users again");
                        //the server UserHandler [RouteBaseAttribute] is set to return Json,
                        //so we need to deserialize it as Json
                        response = await client.Get <List <User> >(getUrl, SerializationToUse.Json);
                        Console.WriteLine("There are currently {0} users", response.Content.Count);
                    }
                    else
                    {
                        Console.WriteLine("DELETE Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#3
0
        /// <summary>
        /// Http : DELETE
        /// </summary>
        public async Task DeletePerson()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {

                    Console.WriteLine("OBTAINING people");
                    string getUrl = string.Format("http://localhost:8001/people");

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml, 
                    //so we need to deserialize it as Xml 
                    var response =
                        await client.Get<List<Person>>("http://localhost:8001/people", SerializationToUse.Xml);
                    Console.WriteLine("There are currently {0} people", response.Content.Count);

                    string deleteUrl = string.Format("http://localhost:8001/people/{0}", 1);

                    var statusCode = await client.Delete(deleteUrl);
                    Console.WriteLine("Http : DELETE");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(deleteUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING people again");
                        //the server PersonHandler [RouteBaseAttribute] is set to return Xml, 
                        //so we need to deserialize it as Xml 
                        response =
                            await client.Get<List<Person>>("http://localhost:8001/people", SerializationToUse.Xml);
                        Console.WriteLine("There are currently {0} people", response.Content.Count);

                    }
                    else
                    {
                        Console.WriteLine("DELETE Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#4
0
        public async Task DeleteUser()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {

                    Console.WriteLine("OBTAINING users");
                    string getUrl = "http://localhost:8001/users/GetAllUsers";

                    //the server UserHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var response = await client.Get<List<User>>(getUrl, SerializationToUse.Json);
                    Console.WriteLine("There are currently {0} users", response.Content.Count);

                    string deleteUrl = string.Format("http://localhost:8001/users/DeleteUserByTheirId/{0}", 1);

                    var statusCode = await client.Delete(deleteUrl);
                    Console.WriteLine("Http : DELETE");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(deleteUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING users again");
                        //the server UserHandler [RouteBaseAttribute] is set to return Json, 
                        //so we need to deserialize it as Json 
                        response = await client.Get<List<User>>(getUrl, SerializationToUse.Json);
                        Console.WriteLine("There are currently {0} users", response.Content.Count);

                    }
                    else
                    {
                        Console.WriteLine("DELETE Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }