The following tutorial demonstrates how to access web services from Microsoft .NET using Visual C#.
To create SOAP and DISH services
Copy the SQL Anywhere sample database from samples-dir to another location, such as c:\webserver\demo.db.
At a command prompt, execute the following statement to start a personal web server. The -xs http(port=80)
option tells the database server to accept HTTP requests on port 80. If you already have a web server running on port 80,
use another port number such as 8080 for this tutorial.
dbeng11 -xs http(port=80) c:\webserver\demo.db |
Start Interactive SQL. Connect to the SQL Anywhere sample database as the DBA. Execute the following statements:
CREATE SERVICE "SASoapTest/EmployeeList" TYPE 'SOAP' AUTHORIZATION OFF SECURE OFF USER DBA AS SELECT * FROM Employees; |
Because authorization has been turned off, anyone can use this service without supplying a user name and password. The commands run under user DBA. This arrangement is simple, but insecure.
CREATE SERVICE "SASoapTest_DNET" TYPE 'DISH' GROUP "SASoapTest" FORMAT 'DNET' AUTHORIZATION OFF SECURE OFF USER DBA; |
The SOAP and DISH service must be of format DNET. In this example, the FORMAT clause was omitted when the SOAP service was created. As a result, the SOAP service inherits the DNET format from the DISH service.
Start Microsoft Visual Studio. Note that this example uses functions from the .NET Framework 2.0.
An empty form appears.
You are presented with a list of the methods available for SASoapTest_DNET. You should see the EmployeeList method.
The Solution Explorer window shows the new web reference.
int sqlCode; listBox1.Items.Clear(); localhost.SASoapTest_DNET proxy = new localhost.SASoapTest_DNET(); DataSet results = proxy.EmployeeList(out sqlCode); DataTableReader dr = results.CreateDataReader(); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { string columnName = dr.GetName(i); try { string value = dr.GetString(i); listBox1.Items.Add(columnName + "=" + value); } catch ( InvalidCastException ) { listBox1.Items.Add(columnName + "=(null)"); } } listBox1.Items.Add(""); } dr.Close(); |
The listbox will display the EmployeeList result set as column name=value pairs.
A try/catch block is included to handle NULL column values such as those found in the TerminationDate column of the Employees table.
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |