Data Types in XML Web Services
See all Sams Teach Yourself on InformIT Web Development Tutorials.
In this hour, you are going to learn about many of the data types that can be used in XML Web services. By the end of this hour you will be able to create services that accept and return primitive data types, arrays, and even classes.
In this hour we will discuss the following:
-
Primitive data types
-
Enumerations
-
Arrays
-
Handling classes
-
Passing arguments ByVal and ByRef
Data Types in .NET
XML Web services offer a wide variety of options when it comes to how you represent and store data, from simple types for storing numbers, such as decimals and integers, to more complex types, such as arrays and classes. Table 10.1 shows some of the common data types in the .NET framework and their Visual Basic (VB) and C# equivalent names.
Table 10.1 Data Types in .NET
Data Type |
Visual Basic Name |
C# Name |
Boolean |
Boolean |
bool |
Byte |
Byte |
byte |
Char |
Char |
char |
Date |
Date |
date |
Decimal |
Decimal |
decimal |
Double |
Double |
double |
_Int32 |
Integer |
int |
_Int64 |
Long |
long |
_Int16 |
Short |
short |
Single |
Single |
float |
String |
String |
String |
The data types that you choose in your XML Web service applications will play a crucial part in their performance. Remember, you are building an application that may be handling hundreds or thousands of requests at any given time; the larger the size of the variables that you use, the more memory your application will require and the slower it will run. Also, remember that in the operation of your service the IIS server and the client applications will be sending data back and forth between each other, and by using the smallest data types possible, you reduce network traffic and increase the efficiency of your apps.
Table 10.2 shows the size of some of the more common data types available to you. From looking at this table, and the data ranges given, you can quickly determine what data best suits your needs. If, for example, you were building a function that returned the number of tickets available at a particular venue and seating in the theater was around three thousand people, you would know to avoid data types such as Decimal and Long.
Table 10.2 Data Type's Sizes and Range
Data Type |
Bytes |
Range |
Boolean |
4 |
True or False |
Byte |
1 |
0 to 255 |
Char |
2 |
0 to 65535 |
Date |
8 |
Jan 1, 1 CE to Dec 31, 9999 |
Decimal |
12 |
79,288,162,154,264,337,593,543,950,335 with no decimal +/E87.9,288,162,154,264,337,593,543,950,335 with decimal |
Double |
8 |
1.79769313486231E308 to 4.94065645841247E-324 AND 4.94065645841247E-324 to 1.79769313486232E308 |
_Int32 |
4 |
2,147,483,648 to 2,147,483,647 |
_Int64 |
8 |
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
_Int16 |
2 |
32,768 to 32,767 |
Single |
4 |
3.402823E38 to 1.401298E-45 OR 1.401298E-45 to 3.402823E38 |
String |
10 + 2/Char |
0 to 2 Billion Characters |