CustomersService Web Service Example

Listing 4. The CustomersService Web Service exposes a single GetCustomer() Web Method that returns a Customer type.

Namespace XmlForAsp

  <ScriptService()> _
  <WebService(Namespace:="http://xmlforasp.net/CustomerService")> _
  <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  Public Class CustomerService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetCustomer(ByVal id As String) As Customer
      'Simulate hitting database to get customer
      Dim cust As New Customer()
      cust.CustomerID = id
      cust.FirstName = "John"
      cust.LastName = "Doe"
      cust.Country = "USA"
      Return cust
    End Function

  End Class

  Public Class Customer

    Private _CustomerID As String
    Public Property CustomerID() As String
      Get
        Return _CustomerID
      End Get
      Set(ByVal value As String)
        _CustomerID = value
      End Set
    End Property


    Private _FirstName As String
    Public Property FirstName() As String
      Get
        Return _FirstName
      End Get
      Set(ByVal value As String)
        _FirstName = value
      End Set
    End Property


    Private _LastName As String
    Public Property LastName() As String
      Get
        Return _LastName
      End Get
      Set(ByVal value As String)
        _LastName = value
      End Set
    End Property


    Private _Country As String
    Public Property Country() As String
      Get
        Return _Country
      End Get
      Set(ByVal value As String)
        _Country = value
      End Set
    End Property


  End Class
End Namespace