Data Types


ASP.NET Web services support all the primitive types supported in the CLR. In addition to the simple primitive types, arrays of primitives are also supported. More interesting, however, is the support for user -defined classes and structs. Essentially, anything that can be represented by an XSD schema can be a parameter or return type of an ASP.NET Web service.

Custom Types

Suppose you want to build an ASP.NET Web service that returns a user-defined class named CustomerRecord . This returns some string and integer values, as well as an array of another, user-defined, class named Order :

  Public Class CustomerRecord   Public Customer As String   Public Address1 As String   Public Address2 As String   Public Phone As String   Public Email As String   Public CustomerOrder(2) As Order   End Class     Public Class Order   Public OrderNumber As Integer   Public Name As String   Public Cost As String   Public ShipDate As String   End Class  

You could write the following WebMethod that returned an instance of CustomerRecord :

  Public Class OrderDetails   <WebMethod()> Public Function RequestOrderDetails() As CustomerRecord   Dim customerRecord As New CustomerRecord   ' Set data...   customerRecord.Customer = "JohnDoe"   customerRecord.Address1 = "22913 Crestpark Dr"   customerRecord.Address2 = "Houston, Tx 79043"   customerRecord.Phone = "281-475-0938"   customerRecord.Email = "john@customer.com"   customerRecord.CustomerOrder(0) = New Order()   customerRecord.CustomerOrder(0).OrderNumber = 12   customerRecord.CustomerOrder(0).Name = "Product A"   customerRecord.CustomerOrder(0).Cost = ".45"   customerRecord.CustomerOrder(0).ShipDate = "8/6/01"     customerRecord.CustomerOrder(1) = New Order()   customerRecord.CustomerOrder(1).OrderNumber = 15   customerRecord.CustomerOrder(1).Name = "Product C"   customerRecord.CustomerOrder(1).Cost = ".41"   customerRecord.CustomerOrder(1).ShipDate = "7/1/01"     Return customerRecord   End Function   End Class  

As long as the user-defined class represents its data using primitive types, and those types are public, the data will be sent correctly to the caller. If, however, the class used Get / Set properties and modified private variables within the class, the data would not be sent correctly “ XML is not used to describe the binary representation of the object in memory. Now that you're more familiar with the data types and the general ASP.NET Web service .asmx file, let's take a deeper look at two of the attributes used most often when building ASP.NET Web services.




Professional ASP. NET 1.1
Professional ASP.NET MVC 1.0 (Wrox Programmer to Programmer)
ISBN: 0470384611
EAN: 2147483647
Year: 2006
Pages: 243

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net