Portus Version 2018-08-24
 

MySQL Tutorials

The MySQL tutorials are based on the World Database. This is a publically available database which is used for MySQL testing and demonstation.

Introduction

You can find out more about the World Database here.

Before starting this tutorial, it is recommended you see the "Getting started with MySQL" section here.

It is assumed that the world database has been set up and and populated as follows

It is also assumed that an ODBC System DSN called "world_dsn" has been set up as follows

We use the user monty to connect to our datasource, but in your instance the user might be different. In many cases, the root user ID is used.

Or on Linux, assuming you are using the unixODBC driver, the following information in your odbc.ini

[world_dsn]
Description     = The world database in mysql
Driver          = DriverMysql
Trace           = off
TraceFile       = stderr
Server          = localhost
Port            = 3306
Database        = world
UserName        =
Password        =

And this information in your odbcinst.ini

[DriverMysql]
Description     = ODBC for MySQL
Driver          = /usr/lib/unixODBC/libmyodbc3.so
Setup           = /usr/lib/unixODBC/libodbcmyS.so
UsageCount      = 1

For more information on setting up an ODBC System DSN, see this section

Finally, it assumed that the Web Service Discovery Wizard has been used to create 3 web services based on the 3 tables in the World database.

Using C# to access MySQL

This tutorial shows how to access the "City" table in MySQL from the C# environment. It assumes a C# environment is available, and some basic knowledge of the C# language.

With a service description (WSDL), a proxy class can be created with the .NET Framework SDK Wsdl.exe tool.

A XML Web service client can then invoke methods of the proxy class, which communicate with Portus over the network by processing the SOAP messages sent to and from Portus server. The proxy class handles the work of mapping parameters to XML elements and then sending the SOAP message over the network.

Wsdl.exe can be used to create proxies for C#, Visual Basic .NET and JScript .NET, for the purpose, we will be generating C#.

These are the steps required to generate the C# wrapper class using Wsdl.exe and create / run a program listing records from the City table using the generated proxy class

  1. From a command prompt, execute Wsdl.exe, specifying the URL / URI of the Portus Web Service to be exposed.

    A single source file is generated, its name is <rootElementName>Service.cs, in this case the "root element" within the XRD is "RootElementName", thus the name of the proxy class source file RootElementNameService.cs

    This file contains a proxy class exposing both synchronous and asynchronous methods for each Web Service operation provided by Portus.

    For instance, for the list operation, the proxy class has the following methods: list, Beginlist, and Endlist. The list method of the proxy class is used to communicate with Portus synchronously, but the Beginlist and Endlist methods are used to communicate with a Portus server asynchronously. For more information about asynchronous communication with a Web Service please refer to the .NET documentation.

  2. Start MS Visual Studio, create a new project with File -> New - Project (or the shortcut Ctrl+Shift+N):

    Create a C# Console Application, assign a name to it, specify the storage location, click OK

    A skeleton class file has been generated into your project workspace, with the required class definition and an empty Main method

  3. First of all, import the generated proxy into the project, right-click on the project name, select Add Existing Item

    select the RootElementNameService.cs proxy file you created earlier, and click Add

    The proxy has been added to the project

    You now need to add a reference to the .NET System.Web.Services component implementing the SOAP interface. In the project explorer, right click on the project name, select Add Reference

    Select System.Web.Services and click OK

  4. Remove the generated code from the newly added class entirely, use (paste) the code from MySQL_City.cs to create your first C# program accessing MySQL Web Service via Portus.

  5. Build the application. Right-click on the project name in the project explorer, click Build

  6. Open a command window, change to the project's build-directory Execute the compiled console application, CityList.exe, the output will look as follows:

  7. This sample selects all Cities records with a ID of 305n, you may want to experiment varying the key data, this is easily done by modifying the properties passed to the generated classes. E.g. try the following to list all records for Cities whose ID start "400".

    key.ID = "400*";

    Or to get a list of all rows in this table:

    key.ID = "*";

Ostia
www.ostiasolutions.com
Copyright @ 2006-2018 Ostia Software Solutions Limited.