In this lesson, you create a Visual C# application to communicate with the web server.
Prerequisites
This lesson assumes that you have set up a web server as instructed in lesson 1. See Lesson 1: Setting up a web server to receive SOAP requests and send SOAP responses.
A recent version of Visual Studio is required to complete this lesson.
This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using Visual C# to access a SOAP/DISH web service.
Context and remarks
This lesson contains several references to localhost. Use the host name or IP address of the web server from lesson 1 instead of localhost if you are not running the web client on the same computer as the web server.
This example uses functions from the .NET Framework 2.0.
Start Visual Studio.
Create a new Visual C# Windows Forms Application project.
An empty form appears.
Add a web reference to the project.
Click Project » Add Service Reference.
In the Add Service Reference window, click Advanced.
In the Service Reference Settings window, click Add Web Reference.
In the Add Web Reference window, type http://localhost:8082/demo/SASoapTest_DNET in the URL field.
Click Go (or the green arrow).
Visual Studio lists the EmployeeList method available from the SASoapTest_DNET service.
Click Add Reference.
Visual Studio adds localhost to the project Web References in the Solution Explorer pane.
Populate the empty form with the desired objects for web client application.
From the Toolbox pane, drag ListBox and Button objects onto the form and update the text attributes so that the form looks similar to the following diagram:
Write a procedure that accesses the web reference and uses the available methods.
Double-click the Employee List button and add the following code for the button click event:
int sqlCode; listBox1.Items.Clear(); localhost.SASoapTest_DNET proxy = new localhost.SASoapTest_DNET(); DataSet results = proxy.EmployeeList(out sqlCode); DataTableReader dr = results.CreateDataReader(); listBox1.BeginUpdate(); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { string dataTypeName = dr.GetDataTypeName(i); string dataName = dr.GetName(i); System.Type ftype = dr.GetFieldType(i); System.TypeCode typeCode = System.Type.GetTypeCode(ftype); string columnName = "(" + dataTypeName + ")" + dataName + "="; if (dr.IsDBNull(i)) { listBox1.Items.Add(columnName + "(null)"); } else { switch (typeCode) { case System.TypeCode.Int32: Int32 intValue = dr.GetInt32(i); listBox1.Items.Add(columnName + intValue); break; case System.TypeCode.Decimal: Decimal decValue = dr.GetDecimal(i); listBox1.Items.Add(columnName + decValue.ToString("c")); break; case System.TypeCode.String: string stringValue = dr.GetString(i); listBox1.Items.Add(columnName + stringValue); break; case System.TypeCode.DateTime: DateTime dateValue = dr.GetDateTime(i); listBox1.Items.Add(columnName + dateValue); break; case System.TypeCode.Boolean: Boolean boolValue = dr.GetBoolean(i); listBox1.Items.Add(columnName + boolValue); break; default: listBox1.Items.Add(columnName + "(unsupported)"); break; } } } listBox1.Items.Add(""); } listBox1.EndUpdate(); dr.Close(); |
Run the application.
Click Debug » Start Debugging.
Communicate with the web database server.
Click Employee List.
The ListBox object displays the EmployeeList result set as (type)name=value pairs. The following output illustrates how an entry appears in the ListBox object:
(Int32)EmployeeID=102 (Int32)ManagerID=501 (String)Surname=Whitney (String)GivenName=Fran (Int32)DepartmentID=100 (String)Street=9 East Washington Street (String)City=Cornwall (String)State=NY (String)Country=USA (String)PostalCode=02192 (String)Phone=6175553985 (String)Status=A (String)SocialSecurityNumber=017349033 (Decimal)Salary=$45,700.00 (DateTime)StartDate=8/28/1984 12:00:00 AM (DateTime)TerminationDate=(null) (DateTime)BirthDate=6/5/1958 12:00:00 AM (Boolean)BenefitHealthInsurance=True (Boolean)BenefitLifeInsurance=True (Boolean)BenefitDayCare=False (String)Sex=F |
The Salary amount is converted to the client's currency format.
Values that contain a date with no time are assigned a time of 00:00:00 or midnight (which is displayed in a format dependent on the client's locale settings).
Values that contain null are tested using the DataTableReader.IsDBNull method.
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0 |