DMU 2015 - 3. semester - oeadm15edD, oeadm15eiC

Weekly plan for Programming
 - please notice: this plan does not include all exercices / project work (normal wednesday and friday)

Theme: Webservice (WCF & WebAPI)  - Go to week: 38, 39, 40, 41

Sidst ændret: 2016.10.03

 

Uge 38
Goals for this week:
  • you will have knowledge about what is a webservice
  • you will be able to make a simple console/windows(wpf) client, witch can access a soap web service (asmx, WCF / svc) using the service reference and have knowledge for  how the classes can be generated from wsdl description (including DTO objects and proxy / service classes).
  • you will be able to create simple web services using WCF service hosted in an ASP.NET application, including you are able to set up the service and data contracts
  • you will be able to test your WCF services using WcfTestClient and by making your own small console / wpf test-clients.

Preparation: Read the materials written in the plan and grab on concepts (details for fotocopies - see fronter) - if you can manage to se the videos from previous lectures you might be ready for the exercises in classroom - you might have some question so prepare those at home.
As the video for demo ect. is only in danish, we will also have the speaks for intro and demo in classroom in english for international students and others that need it, but else you might work with the exercises nearby from the morning.
The exercises is supposed to be in an english version when we start the first lecturer.

 

Dag Tidspunkt Emne Literature / Exercises
Thursday 08:15 - Prepare yourself by reading the material at left igennem and grab on concepts

Vi We will not walk through all the concepts, but only pick up where something is unclear and possible briefly discuss these.

Intro to webservice
- we will shortly talk about the concepts: RPC, RMI, Remoting, CORBA, MS old webservice (asmx)
- Protocols / formats
- WCF

If you want to have a little more speak about the concepts, you can watch this videos from previous (DK)
WebServiceIntro_20111117
(Note finally appear .NET 3.5, where we now must use .NET 4.0 if it is on our webhotel - see fronts) 

  
Distributed object communication (Wikipedia)

Fotocopies (semesterstart - fronter)

C#(*) kap 18.3 (side 884-885) (web-service)

.NET app (**)
- Side 403-409 kap 7.1 Overview
- Side 413-415 kap 7.3 SOAP (intro)
- Side 415-417 kap 7.3.1 SOAP formats
- Side 429-430 kap 7.4.4 Life Cycle of a Web Services (session)
- Side 430-433 kap 7.5 WSDL
- Side 433-434 kap 7.6 UDDI / DISCO

Additional material fromWikipedia
About WebServices
About XML Schema
About SOAP protokollen
About WSDL

The Remote Facade pattern is also relevant in this context
- http://martinfowler.com/eaaCatalog/remoteFacade.html

Slides for the lecture:
Pp_WebServiceBegreber_ENG.ppt  - Samme på dansk 
Pp_WCF_Basic_Intro_ENG.ppt - Samme på dansk  

Extra readings (DK) from Digitaliseringsstyrelsen about IT-Arkitecture.
If you want to go deeper in the terms of SOA and Webservices in DK, you might find this link interesting - http://www.digst.dk/Arkitektur-og-data/It-arkitektur  
 

  Short demo - client using webservices:
We will try to use some webservices (wcf and the older asmx)
- using WcfTestClient.exe
- using Windows klient program

Video from teaching (previous session) for eventual repetition (DK)
  C# SDP14F uge11On WCF intro brug eksisterende i simpel klientprogram (ingen lyd)
Associated solution: 201403120912_KlientSolutionExterneService.zip

 
Pp_WCF_Basic_Client_ENG.ppt - (dansk udgave)
Webservices for exploring - for use in client:
- http://webservicedemo.datamatiker-skolen.dk/
- http://wcfdemo.datamatiker-skolen.dk/
Good "link":
WcfTestClient is a program that by using the WSDL dockument can make it posibly to test a  WCF-service without programming.
You will normal find the WcfTestClient here:
"file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/WcfTestClient.exe"  (VS2015) 
  Exercise - client using webservices:
Try to get data from the following
WcfService (webservice) witch can return objects
-
PersonWcfService.svc

1) You might begin using the WcfTestClient.exe program to get data, witch can show the result directly.
The service contaons the following methods you might try out.
 - GetAllePersoner
 - GetAllePersonerMedNavn
 - GetAllePersonerMedPostnr
 - GetPersonMedPersonnr


2) Make a small client program in the same manner as shown in the demo, where you use the service methods to get data and display the data.
Be attention to Visual Studio will create a Person class based on the WCF service description in the WSDL, so you can by using the first 3 methods receive a collection of Person objects and from the last one a single Person object.

If you know how to use a collection in a WPF GridView you might use this to show the result easily. Remember to set the property AutoGenerateColumns tol true
You might also loop through the collection and write data on the console
 

If more info needed for the exercise check out this description:
- How to: Create a Windows Communication Foundation Client
  2) If you are done, you can continue to make a few small windows programer using some of the webservices at this sites

 

Webservices for exploring - use services in a client:
- http://webservicedemo.datamatiker-skolen.dk/
- http://wcfdemo.datamatiker-skolen.dk/
 
  Short intro - Simple WCF webservice on webserver
WCF service methods
 - endpoint(.svc)
-  interface (ServiceContract and OperationContract)
-  the implementation (code behind)
Short demo - Simple WCF webservice on webserver:
We will make a simple WcfService (webservice) from the beginning

Video from teaching (previous session) for eventual repetition (DK)
  C# SDP14F uge11On WCF intro opret simpel service og klient der bruger den
Associated solution: 201403120912_ServerSolutionMedConsoleKlient.zip
One more video if needed   C# SDP12E - WcfService - del1
 
Pp_WCF_Basic_Server_ENG.ppt - (dansk udgave) -

 

 

  Exercises - Simple WCF webservice on webserver:
1) Start making an empty web-project and create a wcf service (new item) with the name CircleSevice, witch has the following accessibly methods
---- CalcDiameter - witch take radius as input  and return the diameter
---- CalcCircumference - witch take radius as input  and return the diameter Circumference (omkredsen)
---- Make a small client windows program (wpf/winform) - witch use your CircleService
 
If more info needed for the exercise check out this description:
- Getting Started Tutorial - Host the service on WebSite instead of selfhosting - se slides/demo abowe
  Short intro - WCF data objects
WCF service that exchange objects
 - Data Transfer Object (serialiszing using DataContract and DataMember) 
Short demo - WCF data objects:
We will make an small example witch exchange objects
 
Pattern:
- Data Transfer Object
http://msdn.microsoft.com/en-us/library/ff649585.aspx

 

  Exercises with support from theacher - WCF webservice
 - discuss and compare results and helt each other, but also take care of doing individual coding 
Exercise WCF-Valuta  task  a+b+c   (Dansk udgave)
Solve the exercise as simple as possibly - in the exercises there is no updates and therefore you might ignore problem about concurency (threading) and the problems accessing same resources.
 
 
 - 15:30 Possibly. summarizing and student(s) presentation of solutions for the exercies  
MsVC#(*) Microsoft Visual C#.NET Programming, af Doyle
.NET app (**) .Net Application Development, Hanspeter Mössenböck et al

 

Uge 39
Goals for this week:
  • You will have knowledge how to make a statefull webservice by using WCF and ASP.NET Session (per user) & Application (common for all)
  • You will be able to program webservices using WCF hosted in an ASP.NET web-application, including defining neded service and data contracts, besides ensure data survival in memory on server between calls (Statefullness) and thread safe for common data 
  • You will have knowledge about about problems and possible solutions to offline concurrency (optimistic and pesimistic)
  • You will have knowledge about using webservice to transaction scripting

Preparation:

  • Take a second look on the literatur from last week and prepare som questions for outstanding elements
  • Se highlight in plan below for more - danish videos is just an extra option, as they exist I have set them in the plan

 

Dag Tidspunkt Emne Literature / Exercises
Thursday 08:15 - Follow up on last weeks content

Possibly. student(s) presentation of solutions for the exercies from last week
 

 
  Prepare yourself by reading material on left side and grab the concepts

WCF Service continued (Statefullnes and offline concurency)

Serverside (and demand for session on clientside):

We will have a look on how to make data survive in memory (at server) in our WCF services
- For each client (PerSession / ASP.NET Session)
- For the applicationen - commont for all client (Single / ASP.NET Application) - be carefull!! thread safe
We will be concentrating on using ASP.NET Session/Application, and just se the choice of WCF Single/PerSession as orientation

Clientsiden - async:
We will also look at how we can make asynchronous calls from clients, so a user interface is not locked.
It may take time to complete a web service, and here it is appropriate to itself called incl. data transfer can be executed in a background thread, it's easy done with asynchronous calls.
- NB we take the solution with delegates and not Task

From previous year:
WcfServiceSolutionWithSimpleDTO_20140314.zip
WcfServiceSolutionWithSimpleDTO_UdvidetSessionAsync_201403171047.zip
Wpf_DataGrid_Template_i_XAML_201403171206.zip - example with template and databinding on DataGrid  

 



Slides:  Pp_WCF_Session_ENG.ppt - (Dansk udgave)

Example of a WCF service with a user session (ASP.NET) from previous lessons:
- Video (DK) - Vs_WcfSolution_ASPNET_SESSION_20111125.zip

About Application state object: Application State
 


Slides: Pp_WCF_Async_Client_ENG.ppt - (Dansk udgave)

 

 

We will use ASP.NET Session, but if some you would like to hear comment how to uses WCF instanstypes (Single, PerSession and PerCall) - speak about slides on top
- C# SDP12E - WcfService - del2 (DK) 

 

10-12 Exercises without support from theacher - WCF webservice
 - discuss and compare results and helt each other, but also take care of doing individual coding 
Exercise WCF-Valuta  rest of the tasks   (Dansk udgave)
Solve the exercise as simple as possibly - in the exercises a+b+c+d there were no updates and therefore you might ignore problem about concurency (threading) and the problems accessing same resources - in task e you might still have no concurency problem if user is supposed only to convert one amount at the time. In the last two, where all user works on the same data, you must think about concurency.

If you are done you might eventual try to make a solution with the service with the same methods, but using a database instead of data is kept in memory.
 

If you are in complete halt, of cource first use your study group, but if that's not enough you might here have a posibly solution and then restart on your own a couple of time, until you can fulfill a solution without looking at the given solution.
-   - C# SDP12E - WcfService - valutaopave (solution example - DK Speak)
- Vs_ValutaSolution_20141023.zip (code)

Remember it is not the solution that is important, but that you have learned what you need and not at least get routine so you can do the job in a short time. This means sometimes you have to do the job all over again several times to get the training. ''

12:30 Possibly. student(s) presentation of solutions for the exercies
Theacher will not be in for this part - you must organize this yourself
 
 
13:30 ? Prepare yourself by reading material on left side and grab the concepts

WCF Service continued
- follow up
- trådsikring (thread lock)
- offline lock - optimistic / pessimistic

Speak from previous year (DK):
C# SDP12E - Om pessimistisk / optimistisk ofline lock - problemstillingerne og løsningsmulighed 

Relevant pattern from Fowler
- about service layer:
  
http://martinfowler.com/eaaCatalog/serviceLayer.html
- about Optimistic Offline Lock:
  
http://martinfowler.com/eaaCatalog/optimisticOfflineLock.html 
- about Pessimistisk Offline Lock:
 
  
http://martinfowler.com/eaaCatalog/pessimisticOfflineLock.html 
  
     
  Eventual if time - otherwise you have to clear up afterwards with the video / sample programs
- Simple optimistic offline lock when using a database
- Service with database access

Speak from previous year (DK):
C# SDP12E - WcfService og transaction scripting
 
Solution using a database:
- Enkelt Console-eksempel på optimistic offline lock (database)
- Example of  WCF service using database - transactionscripting:
   WcfService_SimpelPersonService_MedDatabase_Solution.zip

 

  Exercise WCF-Valuta  rest of the tasks   (Dansk udgave)
You might still use ofline lock when just having data in memory - it is needed when the last two task is added
 
If you are done you might eventual try to make a solution with the service with the same methods, but using a database instead of data is kept in memory. 
 
 - 15:30 Possibly. summarizing and student(s) presentation of solutions for the exercies
 
 
WCF - more links to tutorials including how to keep state and making WCF restful
- http://dm-webdev.blogspot.dk/2016/10/wcf-links-to-tutorials-including-how-to.html

 

Uge 40
Goals for this week:
  • You get some knowledge of REST as an alternative to SOAP, including json as an alternative to XML for data transport
  • You will be able to program simple Web services using .NET WebAPI
  • You will be able to test simple web service (WebAPI) with direct use of HTTP request - concrete with Fidler and for GET with a browser
  • Eventual - You will have some knowledge how to test your web service (WebAPI) using WebClient and based of using a simple WebApiRequest javascript template

Preparation:

Prepare yourself by watching the first part of the video below - what's going on and take some notes.
You must skip where he talks about html and other GUI for this time, as we only should work with services for now.
Concentrate about to make WebAPI and test them with Fiddler
Thursday, use the video to help you get started.
Introduction for WebApi - including something about om REST
- video tutorials ASP.NET Web API - Pluralsight (Jon Flanders)

Read briefly about WCF versus WebApi: https://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx

Tool for debuging af HTTP - should be used for testing WebApi - install before Thursday
Download Fiddler Web Debugging Tool for Free by Telerik 
 

Next tutorials might be a supplement if you need more
- video tutorials ASP.NET Web API - Getting Started , By Scott Hanselman (Channel9 - Microsoft)
- Getting Started with ASP.NET Web API 2 (C#):  https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
- eventual supplement explaning more about REST: Pluralsight REST Fundamentals
 

Dag Tidspunkt Emne Literature / Exercises
Thursday
08:15 -

 

Possibly. summarizing and student(s) presentation of solutions for the exercies from last week  
  Short discussion about terms for WebApi
 
 
  Demo med simpel Web API
- test client using GET with browser
- test client using Fiddler
- C# client using WebClient
  
Pp_WebApi_Basic_Server_og_Client_ENG.ppt - (Dansk udgave)

To reduce complexity of VS template for WebApi
Use this project as template for the exercises (not include all MVC)
WebApiSolution_BasicTemplate.zip

  

  Exercise - WebApi webservices:
Make webservice for Curency exercise WCF-Valuta  -  (Dansk udgave) - this time using WebApi
 - test your WebApi using Fidler
You might eventual drop execices witch needs Session, as you normal will try to prevent session when using REST / Web API
  
Se preparation
12:15 WebApi continued
- common data for more clients
- Simpel javascript client for test of WebApi services
- Routning og Action  (eventual first next week)
 
Routing in ASP.NET Web API
Slides about routing, Action, simpel WebApi tester, Session
 - Pp_WebApi_ActionRoutning_og_TestClient_Session_ENG.ppt - (Dansk udgave)
Template for client to testing WebApi (insert html file on web-site with WebApi and correct for your test)
- WebApiTestRequestTemplate.html.zip

A posibly solution if you get halt in your exercise
WebApiSolution_BasicGetPutReposityLock_MedTest_20151021.zip
Remember it is not the solution that is important, but that you have learned what you need and not at least get routine so you can do the job in a short time. This means sometimes you have to do the job all over again several times to get the training. ''
 
  If you want go deeper this will contain more reading about attribute routing
- http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
 - 15:30 Possibly. summarizing and student(s) presentation of solutions for the exercies  
WebApi - more links to tutorials
-
http://dm-webdev.blogspot.dk/2016/10/webapi-links-to-tutorials.html

 

 

 
Uge 41 - preliminary
Goals for this week:
  • You will be able to program simple Web services using .NET WebAPI and test them
  • You will be able to use Routning and Action in your WebApi for controling the access
  • You will be able to handle to return error-messages from a WebApi

Preparation:  

Prepare yourself by writing questions you need an answer of regarding WCF and WebApi primary based on the need to finish the exercises.
Prepare yourself on a presentation of your solutions of exercises (WCF and WebApi) - the state they must be in if not finish
Read about WebApi errorhandling se below.
 

Dag Tidspunkt Emne Literature / Exercises
Torsdag 08:15 - Students presentation of solutions for the exercies from last week and WCF

We will split class in english / danish (eventual 2) so you should not present for all and we can keep presentation and discussion in danish for danish students - and of course english for the international students

While one class is presenting the other will work with finish the exercise and if finish with your project.
 
 
  WepApi continued
- ErrorHandling
https://www.asp.net/web-api/overview/error-handling/exception-handling
  Exercise - WebApi webservices from last week continued
You should try some of your WebApi with 
- Fidler (se last week)
- WebClient (se last week)
- JavaScript template (se last week)
 
 
 - 15:30 Eventual we might have a look on how to setup WCF to work with REST / json (not done)