====== Web service design, implementetion and testing ====== * Sluzba s protokolem SOAP je dostupna na [[http://taskmanager.borovicka.name/services/TMService.svc|zde]] . * Sluzba s protokolem REST je dostupna na [[http://taskmanager.borovicka.name/services/TMRESTService.svc|zde]] ===== Design ===== * Pro realizaci webove sluzby jsem se rozhodli pouzit Windows Communication Foundation (WCF). * WCF je framework zamerujici se na service oriented communication, ktery umoznuje vzajemnou komunikaci sluzeb pres ruzna rozhrani, at jiz SOAP, P2P a radu dalsich. * Abychom si vyzkoušeli obě technologie pro srovnání, implementovali jsme jednu službu s protokolem SOAP a jednu s REST. * Obě webové služby implementují perzistenci přes session. Tj. funguje zde klasický webový model - přihášení -> práce -> odhlášení. * Pokud uživatel není přihlášen, nebo není v roli, která má pro danou metodu práva, není mu umožněno tuto metodu použít. ==== Application layers ==== {{taskmanagerarchitecture.png|}} ===== Implementation ===== ==== SOAP Service ==== === Poskytovane metody === * LogIn * LogOut * GetAllUsers * GetAllProjects * GetAllProjects * GetTasksInProject * **GetTaskById** - READ * **AddTask** - CREATE * **UpdateTask** - UPADTE * **CloseTask** - DELETE * AddAnswer * GetTaskAnswers * GetUserById === Service contract === [ServiceContract] public interface ITaskManagerService { [OperationContract] string LogIn(string login, string password); [OperationContract] void LogOut(); [OperationContract] DataUser[] GetAllUsers(); [OperationContract] DataProject[] GetAllProjects(); [OperationContract] DataTask[] GetTasksInProject(int projectId); [OperationContract] DataTask GetTaskById(int id); [OperationContract] DataTask AddTask(int projectId, string name, int priorityId, string description, DateTime deadline, List usersIds); [OperationContract] DataTask UpdateTask(int taskId, string name, int priorityId, string description, DateTime deadline, List userIds, int stateId); [OperationContract] void CloseTask(int taskId); [OperationContract] void AddAnswer(int taskId, string name, string text); [OperationContract] DataAnswer[] GetTaskAnswers(int taskId); [OperationContract] DataUser GetUserById(int id); } ==== Testing ==== * Pro testovani jsme pouzili [[http://msdn.microsoft.com/en-us/library/bb552364.aspx|WcfTestClient]], ktery je soucasti WCF Development Tools a umoznuje uplne testovani webove sluzby pomoci UI. === Ukazka komunikace === * Priklad ukazuje komunikaci pri volani funkce //**GetTaskById(int id)**//. == Request == http://tempuri.org/ITaskManagerService/GetTaskById 6 == Response == dsadsdasd 6 Task2 3 3 ==== REST service ==== === Poskytovane metody === * LogIn * LogOut * GetMyInfo * GetAllProjects * **GetTasksInProject** - READ * **CreateProject** - CREATE * **CloseTask** - UPDATE === Service contract === /// /// Verifies specified credentials and logs the user into the system if valid. /// /// The login. /// The password. /// The error object. /// /// Returns true if the specified credentials are valid and the login process was successfull. /// Returns false otherwise. /// If an error occurs, the err param is filled with the error info. /// [OperationContract] [WebGet(UriTemplate = "/LogIn/{login}/{password}", BodyStyle = WebMessageBodyStyle.WrappedResponse)] bool LogIn(string login, string password, out ErrorInfo err); /// /// Logs the current user out of the application. New LogIn will be required to proceed with any other operations. /// [OperationContract] [WebGet(UriTemplate = "/LogOut")] void LogOut(); /// /// Gets information about currently logged user. /// /// The error object. /// /// Returns new DataUser object with information about the current user. /// If an error occurs, the err param is filled with the error info. /// [OperationContract] [WebGet(UriTemplate = "/GetMyInfo", BodyStyle = WebMessageBodyStyle.WrappedResponse)] DataUser GetMyInfo(out ErrorInfo err); /// /// Gets a list of all projects. /// /// List of DataProject objects representing all Projects in the application. [OperationContract] [WebGet(UriTemplate = "/GetAllProjects")] List GetAllProjects(); /// /// Creates a new project. /// /// The name of the project. /// Returns a newly created instance of DataProject. [OperationContract] [WebGet(UriTemplate = "/CreateProject/{name}")] DataProject CreateProject(string name); /// /// Gets all tasks in project with specified id. /// /// The id of the project to get the tasks for. /// List of DataTask objects representing all tasks in the project with specified id. [OperationContract] [WebGet(UriTemplate = "/GetTasksInProject/{id}")] List GetTasksInProject(string id); /// /// Sets the state of taks with the specified id to closed. /// /// The task id. /// Newly updated DataTask object. [OperationContract] [WebGet(UriTemplate = "/CloseTask/{taskId}")] DataTask CloseTask(string taskId); ==== Testing ==== * Pro testovani jsme použili webový prohlížeč, konkrétně Mozilla Firefox, který umí zobrazit strukturu XML v odpovědi od webové služby. === Ukázka komunikace === * Příklad ukazuje komunikaci při volání funkce //**GetTasksInProject(string id)**//. == Request == GET http://taskmanager.borovicka.name/Services/TMRESTService.svc/GetTasksInProject/1 == Response == desca55 5 Task number 5!!! 1 1 sdsdsd 9 asdsddfdf 1 1 joooxx 10 super task2 1 1 pop 11 popop 1 1 vvvv 12 aaa 1 1