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
From a command prompt, execute Wsdl.exe, specifying the URL / URI of 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 Portus server asynchronously. For more information about asynchronous communication with a Web Service please refer to the .NET documentation.
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
A skeleton class file has been generated into your project workspace, with the required class definition and an empty Main method
First of all, import the generated proxy into the project, right-click on the project name, select Existing Item
select the RootElementNameService.cs proxy file you created earlier, and click
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
Select System.Web.Services and click
Remove the generated code from the newly added class entirely, use (paste) the code from MySQL_CityDemo.cs to create your first C# program accessing MySQL Web Service via Portus.
Build the application. Right-click on the project name in the project explorer, click
Open a command window, change to the project's build-directory Execute the compiled console application, CityList.exe, the output will look as follows:
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 = "*";