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

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var response = await client.Get <Account>(getUrl, SerializationToUse.Json);
                    var account  = response.Content;
                    Console.WriteLine(account);

                    string newAccountNumber = string.Format("{0}_Modified_{1}",
                                                            account.AccountNumber, DateTime.Now.Ticks);
                    account.AccountNumber = newAccountNumber;

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

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var statusCode = await client.Put(putUrl, account, SerializationToUse.Json);
                    Console.WriteLine("Http : PUT");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(putUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING accounts/1 again");
                        response = await client.Get <Account>(getUrl, SerializationToUse.Json);
                        account  = response.Content;
                        Console.WriteLine(account);
                    }
                    else
                    {
                        Console.WriteLine("PUT Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#2
0
        /// <summary>
        /// Http : GET
        /// Gets all items in the collection
        /// </summary>
        public async Task GetPeople()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string getUrl = "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> >(getUrl, SerializationToUse.Xml);
                    Console.WriteLine("Http : GET");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(getUrl);
                    Console.WriteLine(response.Content.Count);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#3
0
        /// <summary>
        /// Http : GET/{id}
        /// Gets item with the id specified
        /// </summary>
        public async Task GetUser(int id)
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string getUrl = string.Format("http://localhost:8001/users/GetUserByTheirId/{0}", id);

                    //the server UserHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json
                    var response = await client.Get<User>(getUrl, SerializationToUse.Json);
                    Console.WriteLine("Http : GET/{id}");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(getUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#4
0
        /// <summary>
        /// Http : GET
        /// Gets all items in the collection
        /// </summary>
        public async Task GetPeople()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string getUrl = "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>>(getUrl, SerializationToUse.Xml);
                    Console.WriteLine("Http : GET");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(getUrl);
                    Console.WriteLine(response.Content.Count);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#5
0
        /// <summary>
        /// Http : GET/{id}
        /// Gets item with the id specified
        /// </summary>
        public async Task GetAccount(int id)
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string getUrl = string.Format("http://localhost:8001/accounts/{0}", id);

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var response = await client.Get <Account>(getUrl, SerializationToUse.Json);
                    Console.WriteLine("Http : GET/{id}");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(getUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#6
0
        /// <summary>
        /// Http : PUT
        /// </summary>
        public async Task PutUser()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    Console.WriteLine("OBTAINING users/GetUserByTheirId/1");
                    string getUrl = string.Format("http://localhost:8001/users/GetUserByTheirId/{0}", 1);

                    //the server UserHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var response = await client.Get <User>(getUrl, SerializationToUse.Json);
                    var user     = response.Content;
                    Console.WriteLine(user);

                    string newUserName = string.Format("{0}_Modified_{1}", user.UserName, DateTime.Now.Ticks);
                    user.UserName      = newUserName;

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

                    //the server UserHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var statusCode = await client.Put(putUrl, user, SerializationToUse.Json);
                    Console.WriteLine("Http : PUT");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(putUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING users/GetUserByTheirId/1 again");
                        response = await client.Get <User>(getUrl, SerializationToUse.Json);
                        user     = response.Content;
                        Console.WriteLine(user);
                    }
                    else
                    {
                        Console.WriteLine("PUT Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#7
0
        /// <summary>
        /// Http : PUT
        /// </summary>
        public async Task PutPerson()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    Console.WriteLine("OBTAINING people/1");
                    string getUrl = string.Format("http://localhost:8001/people/{0}", 1);

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml,
                    //so we need to deserialize it as Xml
                    var response = await client.Get <Person>(getUrl, SerializationToUse.Xml);
                    var person   = response.Content;
                    Console.WriteLine(person);

                    string newLastName = string.Format("{0}_Modified_{1}", person.LastName, DateTime.Now.Ticks);
                    person.LastName    = newLastName;

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

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml,
                    //so we need to deserialize it as Xml
                    var statusCode = await client.Put(putUrl, person, SerializationToUse.Xml);
                    Console.WriteLine("Http : PUT");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(putUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING people/1 again");
                        response = await client.Get <Person>(getUrl, SerializationToUse.Xml);
                        person   = response.Content;
                        Console.WriteLine(person);
                    }
                    else
                    {
                        Console.WriteLine("PUT Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#8
0
        /// <summary>
        /// Http : POST
        /// </summary>
        public async Task PostUser()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string postUrl   = "http://localhost:8001/users/AddASingleUser";
                    User newUser     = new User();
                    newUser.UserName = string.Format("UserName_{0}", DateTime.Now.Ticks);

                    //the server UserHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var response = await client.Post <User>(postUrl, newUser, SerializationToUse.Json);
                    Console.WriteLine("Http : POST");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(postUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#9
0
        /// <summary>
        /// Http : POST
        /// </summary>
        public async Task PostAccount()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string postUrl           = "http://localhost:8001/accounts";
                    Account newAccount       = new Account();
                    newAccount.SortCode      = string.Format("SortCode_{0}", DateTime.Now.Ticks);
                    newAccount.AccountNumber = string.Format("AccountNumber_{0}", DateTime.Now.Ticks);

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json,
                    //so we need to deserialize it as Json
                    var response = await client.Post <Account>(postUrl, newAccount, SerializationToUse.Json);
                    Console.WriteLine("Http : POST");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(postUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#10
0
        /// <summary>
        /// Http : POST
        /// </summary>
        public async Task PostUser()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string postUrl = "http://localhost:8001/users/AddASingleUser";
                    User newUser = new User();
                    newUser.UserName = string.Format("UserName_{0}", DateTime.Now.Ticks);

                    //the server UserHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var response = await client.Post<User>(postUrl, newUser, SerializationToUse.Json);
                    Console.WriteLine("Http : POST");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(postUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");

                }
            });
        }
示例#11
0
        /// <summary>
        /// Http : POST
        /// </summary>
        public async Task PostPerson()
        {
            await Task.Run(async() =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string postUrl      = "http://localhost:8001/people";
                    Person newPerson    = new Person();
                    newPerson.FirstName = string.Format("FirstName_{0}", DateTime.Now.Ticks);
                    newPerson.LastName  = string.Format("LastName_{0}", DateTime.Now.Ticks);

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml,
                    //so we need to deserialize it as Xml
                    var response = await client.Post <Person>(postUrl, newPerson, SerializationToUse.Xml);
                    Console.WriteLine("Http : POST");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(postUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");
                }
            });
        }
示例#12
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("=================================");
                }
            });
        }
示例#13
0
        /// <summary>
        /// Http : POST
        /// </summary>
        public async Task PostAccount()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string postUrl = "http://localhost:8001/accounts";
                    Account newAccount = new Account();
                    newAccount.SortCode = string.Format("SortCode_{0}", DateTime.Now.Ticks);
                    newAccount.AccountNumber = string.Format("AccountNumber_{0}", DateTime.Now.Ticks);

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var response = await client.Post<Account>(postUrl, newAccount, SerializationToUse.Json);
                    Console.WriteLine("Http : POST");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(postUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");

                }
            });
        }
示例#14
0
        /// <summary>
        /// Http : POST
        /// </summary>
        public async Task PostPerson()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {
                    string postUrl = "http://localhost:8001/people";
                    Person newPerson = new Person();
                    newPerson.FirstName = string.Format("FirstName_{0}", DateTime.Now.Ticks);
                    newPerson.LastName = string.Format("LastName_{0}", DateTime.Now.Ticks);

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml, 
                    //so we need to deserialize it as Xml 
                    var response = await client.Post<Person>(postUrl, newPerson, SerializationToUse.Xml);
                    Console.WriteLine("Http : POST");
                    Console.WriteLine("Status Code : {0}", response.StatusCode);
                    Console.WriteLine(postUrl);
                    Console.WriteLine(response.Content);
                    Console.WriteLine("=================================");

                }
            });
        }
示例#15
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("=================================");
                }
            });
        }
示例#16
0
        /// <summary>
        /// Http : PUT
        /// </summary>
        public async Task PutUser()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {

                    Console.WriteLine("OBTAINING users/GetUserByTheirId/1");
                    string getUrl = string.Format("http://localhost:8001/users/GetUserByTheirId/{0}", 1);

                    //the server UserHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var response = await client.Get<User>(getUrl, SerializationToUse.Json);
                    var user = response.Content;
                    Console.WriteLine(user);

                    string newUserName = string.Format("{0}_Modified_{1}", user.UserName, DateTime.Now.Ticks);
                    user.UserName = newUserName;

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

                    //the server UserHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var statusCode = await client.Put(putUrl, user, SerializationToUse.Json);
                    Console.WriteLine("Http : PUT");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(putUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING users/GetUserByTheirId/1 again");
                        response = await client.Get<User>(getUrl, SerializationToUse.Json);
                        user = response.Content;
                        Console.WriteLine(user);

                    }
                    else
                    {
                        Console.WriteLine("PUT Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#17
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("=================================");
                }
            });
        }
示例#18
0
        /// <summary>
        /// Http : PUT
        /// </summary>
        public async Task PutPerson()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {

                    Console.WriteLine("OBTAINING people/1");
                    string getUrl = string.Format("http://localhost:8001/people/{0}", 1);

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml, 
                    //so we need to deserialize it as Xml 
                    var response = await client.Get<Person>(getUrl, SerializationToUse.Xml);
                    var person = response.Content;
                    Console.WriteLine(person);

                    string newLastName = string.Format("{0}_Modified_{1}", person.LastName, DateTime.Now.Ticks);
                    person.LastName = newLastName;

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

                    //the server PersonHandler [RouteBaseAttribute] is set to return Xml, 
                    //so we need to deserialize it as Xml 
                    var statusCode = await client.Put(putUrl, person, SerializationToUse.Xml);
                    Console.WriteLine("Http : PUT");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(putUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING people/1 again");
                        response = await client.Get<Person>(getUrl, SerializationToUse.Xml);
                        person = response.Content;
                        Console.WriteLine(person);

                    }
                    else
                    {
                        Console.WriteLine("PUT Failed");
                    }
                    Console.WriteLine("=================================");
                }
            });
        }
示例#19
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("=================================");
                }
            });
        }
示例#20
0
        /// <summary>
        /// Http : PUT
        /// </summary>
        public async Task PutAccount()
        {
            await Task.Run(async () =>
            {
                using (RESTWebClient client = new RESTWebClient())
                {

                    Console.WriteLine("OBTAINING accounts/1");
                    string getUrl = string.Format("http://localhost:8001/accounts/{0}", 1);

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var response = await client.Get<Account>(getUrl, SerializationToUse.Json);
                    var account = response.Content;
                    Console.WriteLine(account);

                    string newAccountNumber = string.Format("{0}_Modified_{1}",
                        account.AccountNumber, DateTime.Now.Ticks);
                    account.AccountNumber = newAccountNumber;

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

                    //the server AccountHandler [RouteBaseAttribute] is set to return Json, 
                    //so we need to deserialize it as Json 
                    var statusCode = await client.Put(putUrl, account, SerializationToUse.Json);
                    Console.WriteLine("Http : PUT");
                    Console.WriteLine("Status Code : {0}", statusCode);
                    Console.WriteLine(putUrl);

                    if (statusCode == HttpStatusCode.OK)
                    {
                        Console.WriteLine("OBTAINING accounts/1 again");
                        response = await client.Get<Account>(getUrl, SerializationToUse.Json);
                        account = response.Content;
                        Console.WriteLine(account);

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