Home > Articles > Web Services

  • Print
  • + Share This
This chapter is from the book

Handling Primitive Data Types

Create a new XML Web services project and call it DataTypes. You can use this project to test all of the different data type handling methods that you will learn in this hour.

In the examples that you have seen so far in this book, only primitive data types have been returned. By this point, you should be fairly familiar with their use. Any of the primitive data types, such as Integer, String, or Long, can be returned in exactly the same manner.

Listing 10.1 shows an example of a method that returns a string. To return any other type, you would simply alter line 1 of the function declaration to return any of the other data types in Table 10.1.

Listing 10.1 Returning a Simple Data Type in VB

1:  <WebMethod()> Public Function StringReturn() As String
2:    Return "This is a string"
3:  End Function

Listing 10.2 shows the equivalent function in C#. Again, you can use this method as a template to return any of the data types shown in Table 6.1.

Listing 10.2 Returning a Simple Data Type in C#

1:  [WebMethod]
2:  public string StringReturn()
3:  {
4:   return "This is a string";

5: }

  • + Share This
  • 🔖 Save To Your Account