ZiBaT => Peter Levinsky => Programming => exercise

SOAP
SOAP-service
with DataBase- part4

Updated : 2016-09-26

Exercise: SOAP based web services With DataBase- Part 4

Mission:

To design and implement your own SOAP service using databases for persistence.

This is a refactoring of SOAP-service 3 to use database as persistence for storing sensor information.

Precondition:

The exercise Create you own SOAP-service part3

Exercise A: create A DataBase for storing Sensor data

In your SQL object browser create a new database e.g. 'SensorDB'.

Create a table to hold Sensor Data i.e. (light, temperature, timestamp).

Add some data rows (i.e right click on table and pick view data, then you can add data)

Get the connectionstring i.e. right click on database pick properties pick connection-string

 

Exercise B: Add connection to database from WCF-project

To retrieve and store data from and to the database you can use ADO.Net and SQL statements OR use the buildt in entity framework.
Which one you choose is up to you :-)

If you using ado.net it see https://msdn.microsoft.com/en-us/library/dw70f090(v=vs.110).aspx

Brief:

  1. Create a SQLConnection - using the connectionstring
  2. Open SQLConnection
  3. Create a SQLCommand using SQL
  4. Execute the SQLCommand

if you are using Enitity framework see https://www.tutorialspoint.com/entity_framework/entity_database_first_approach.htm

Brief:

  1. Create a new Item i.e. right click on project -> add new item -> data -> ADO.NET entity -> code first from database
    -> new connection -> fill in databaser server (see in connection string) + select database -> pick tables to use
  2. Create an instance of your model e.g. Model1 db = new Model1();
  3. Get information from database e.g. db.SensorDatas

You can use other posibilities like Linq, ...

Exercise C: Refactor the interface methods to use the Database

The two types:

StoreData : e.g. db.SensorDatas.Add( << the object >>) -- perhaps you need to convert the incomming object to the DB-object

GetData : e.g. db.SensorDatas -- this is the list of data - again perhaps you need to convert the DB-object to the outgoing object

 

Additional Exercise D: retrieve data from sensor and store in database through SOAP

Make a console application that retrieves UDP-datagrams and forward these to the SOAP.

You need to be at the EGV-DMU2 network !!!!

The UDP broadcast are to port 7080

The format is

light: 45
temp: 20
timestamp: YYYY-MM-DD-hh-mm-ss