Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

<script runat="template">
Public Enum StateEnum
    STARTED
    STOPPED
    DISABLED
End Enum</script>

Now you can use a CodeSmith Property directive to define a property that makes use of the new type:

...

Public Function GetState (ByVal State As StateEnum) As String
    Select Case State
        Case StateEnum.STARTED
            GetState = "STARTED"
        Case StateEnum.STOPPED
            GetState = "STOPPED"
        Case StateEnum.DISABLED
            GetState = "DISABLED"
    End Select
End Function

Having done this, you can get the string corresponding to the user's choice of InitialState property by inserting <%= GetState(InitialState) %> anywhere in the template. After adding enumerations, properties, and helper functions for the authentication and port properties, here's the current state of our template:

<%@ CodeTemplate Language="VB" TargetLanguage="T-SQL" Description="Create an HTTP Endpoint." %>
<%@ Property Name="InitialState" Type="StateEnum" Category="Options" Default="STARTED" Description="The initial state of the Web service." %>
<%@ Property Name="Authentication" Type="AuthenticationEnum" Category="Options" Default="INTEGRATED" Description="Authentication method." %>
<%@ Property Name="Port" Type="PortsEnum" Category="Options" Default="CLEAR" Description="Port to use." %>
CREATE PROC dbo.PersonAddressTypeProc
AS
    SELECT 
    AddressTypeID, 
    Name, 
    rowguid, 
    ModifiedDate
    FROM
    Person.AddressType
GO
CREATE ENDPOINT GetAddressType
    STATE = <%= GetState(InitialState) %>
AS HTTP
(
    PATH = '/AddressType',
    AUTHENTICATION = (<%= GetAuthentication(Authentication) %>),
    PORTS = (<%= GetPort(Port) %>),
    SITE = 'localhost'
)
FOR SOAP
(
    WEBMETHOD 'AddressTypeList'
        (NAME='AdventureWorks.dbo.PersonAddressTypeProc'),
    BATCHES = DISABLED,
    WSDL = DEFAULT,
    DATABASE = 'AdventureWorks',
    NAMESPACE = 'http://AdventureWorks/AddressType'
)
GO
<script runat="template">
Public Enum StateEnum
    STARTED
    STOPPED
    DISABLED
End Enum 

Public Enum AuthenticationEnum
    BASIC
    DIGEST
    NTLM
    KERBEROS
    INTEGRATED
End Enum 

Public Enum PortsEnum
    CLEAR
    SSL
End Enum 

Public Function GetState (ByVal State As StateEnum) As String
    Select Case State
        Case StateEnum.STARTED
            GetState = "STARTED"
        Case StateEnum.STOPPED
            GetState = "STOPPED"
        Case StateEnum.DISABLED
            GetState = "DISABLED"
    End Select
End Function 

Public Function GetAuthentication (ByVal Authentication As AuthenticationEnum) As String
    Select Case Authentication
        Case AuthenticationEnum.BASIC
            GetAuthentication = "BASIC"
        Case AuthenticationEnum.DIGEST
            GetAuthentication = "DIGEST"
        Case AuthenticationEnum.NTLM
            GetAuthentication = "NTLM"
        Case AuthenticationEnum.KERBEROS
            GetAuthentication = "KERBEROS"
        Case AuthenticationEnum.INTEGRATED
            GetAuthentication = "INTEGRATED"
    End Select
End Function 

Public Function GetPort (ByVal Port as PortsEnum) As String
    Select Case Port
        Case PortsEnum.CLEAR
            GetPort = "CLEAR"
        Case PortsEnum.SSL
            GetPort = "SSL"
    End Select
End Function
</script>

So far, so good. But there's still one thing missing: a connection to the database. We'll tackle that next.

Next: Setting up a SQL Property

More information:

The Property Directive