Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » SQL Anywhere Web Services

Creating SOAP and DISH web services Next Page

Tutorial: Accessing web services from Microsoft .NET

The following tutorial demonstrates how to access web services from Microsoft .NET using Visual C#.

To create SOAP and DISH services
  1. Copy the SQL Anywhere sample database from samples-dir to another location, such as c:\webserver\demo.db.

  2. 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. If you already have a web server running on port 80, use another port number such as 8080 for this tutorial.

    dbeng10 -xs http(port=80) c:\webserver\demo.db
  3. Start Interactive SQL. Connect to the SQL Anywhere sample database as the DBA. Execute the following statements:

    1. Define a SOAP service that lists the Employees table.

      CREATE SERVICE "SASoapTest/EmployeeList"
      TYPE 'SOAP'
      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.

    2. Create a DISH service to act as a proxy for the SOAP service and to generate the WSDL document.

      TYPE 'DISH'
      GROUP "SASoapTest"
      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.

  4. Start Microsoft Visual C#. Note that this example uses functions from the .NET Framework 2.0.

    1. Create a new Windows Application project.

      An empty form appears.

    2. From the Project menu, choose Add Web Reference.

    3. In the URL field of the Add Web Reference page, enter the following URL: http://localhost:80/demo/SASoapTest_DNET.

    4. Click Go.

      You are presented with a list of the methods available for SASoapTest_DNET. You should see the EmployeeList method.

    5. Click Add Reference to finish.

      The Solution Explorer window shows the new Web Reference.

    6. Add a ListBox and a Button to the form as shown in the following diagram.

      SOAP demonstration form.
    7. Rename the button text to Employee List.

    8. Double-click the Employee List button and add the following code for the button click event.

      int sqlCode;
      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);
          string value = dr.GetString(i);
    9. Build and run the program.

      The listbox will display the EmployeeList result set as column name=value pairs.