Data Types

ASP.NET web services can use any CLR-supported primitive data type as a parameter or a return value. Table 15-2 summarizes the valid types.

Table 15-2. CLR-supported primitive data types

Type

Description

byte

1-byte unsigned integer

short

2-byte signed integer

int

4-byte signed integer

long

8-byte signed integer

float

4-byte floating point

double

8-byte floating point

decimal

16-byte floating point

bool

True/false

char

Single Unicode character

string

Sequence of Unicode characters

DateTime

Represents dates and times

object

Any type

In addition to the primitive data types, you can use arrays and ArrayLists of the primitive types. Since data is passed between a web service and its clients using XML, whatever is used as either a parameter or return value must be represented in an XML schema or XSD.

Arrays

The examples shown so far in this chapter have used simple primitive types, such as strings and numbers, as parameters and return values. You can also use an array of primitive types as in the code shown here:

    [WebMethod]
    public string[] GetArray()
    {
       string[] TestArray = {"a","b","c"};
       return TestArray;
    }

The main limitation of using arrays, of course, is that you must know the number of elements at design time. If the number of elements is dynamic, then an ArrayList will be called for. If an ArrayList is used in the web service, it will be converted to an object array when the web service description is created. The client ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.